{"record":{"id":"6066534cb91f885f","repo":"instructure/canvas-lms","slug":"validation-error-filename","errorCode":null,"errorMessage":"validation_error_filename","messagePattern":"validation_error_filename","errorType":"validation","errorClass":"StandardError","httpStatus":null,"severity":"error","filePath":"app/models/accessibility/rules/img_alt_rule_helper.rb","lineNumber":65,"sourceCode":"      end\n\n      def self.validation_error_too_long\n        I18n.t(\"Keep alt text under %{max_length} characters.\", max_length: MAX_LENGTH)\n      end\n\n      def self.fix_alt_text!(elem, value)\n        if value.nil?\n          elem[\"role\"] = \"presentation\"\n          elem[\"alt\"] = \"\"\n          return { changed: elem, content_preview: adjust_img_style(elem) }\n        end\n\n        if value.to_s.strip.empty?\n          raise StandardError, validation_error_missing\n        end\n\n        if filename_like?(value)\n          raise StandardError, validation_error_filename\n        end\n\n        if value.length > MAX_LENGTH\n          raise StandardError, validation_error_too_long\n        end\n\n        elem[\"alt\"] = value\n        { changed: elem, content_preview: adjust_img_style(elem) }\n      end\n    end\n  end\nend\n","sourceCodeStart":47,"sourceCodeEnd":78,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/models/accessibility/rules/img_alt_rule_helper.rb#L47-L78","documentation":"ImgAltRuleHelper rejects alt text that looks like a filename (via filename_like?). Filenames such as 'image.png' or 'IMG_1234.jpg' are not meaningful alt text, so the accessibility rule raises StandardError with the validation_error_filename message to force the author to describe the image instead.","triggerScenarios":"Calling the img alt fix with a value that filename_like? classifies as a filename (e.g. contains extensions like .png/.jpg, CamelCase-with-digits patterns); user pastes the uploaded file's name into the alt field.","commonSituations":"Course authors leaving the default filename in the alt text box; bulk migration scripts copying title attributes containing file names into alt; CMS imports preserving original upload names.","solutions":["Replace the filename with a human description of the image's content","Adjust input so the user cannot submit while the value matches the filename heuristic","If the heuristic false-positives on legitimate text, rewrite the value so it doesn't match the pattern (e.g. remove extension-like suffix)","Rescue the error and re-prompt the user for a description"],"exampleFix":"// before\nfix(elem, 'IMG_2049.jpg')\n// after\nfix(elem, 'Students collaborating in a lab')","handlingStrategy":"validation","validationCode":"const FILENAME_RE = /\\.[a-z0-9]{2,4}$/i;\nif (FILENAME_RE.test(alt_text.trim())) {\n  alert('Describe the image, do not use the file name'); return;\n}\nsubmitFix(elem, alt_text)","typeGuard":"const isDescriptive = (v) => typeof v === 'string' && v.trim().length > 0 && !/\\.\\w{2,4}$/.test(v.trim())","tryCatchPattern":"begin\n  helper.fix(elem, value)\nrescue StandardError => e\n  flash[:error] = e.message\n  redirect_back\nend","preventionTips":["Never prefill alt fields with the uploaded file's name","Warn inline as the user types if the value matches filename heuristics","Educate authors that alt text describes content, not origin"],"tags":["accessibility","validation","ruby"],"backgroundTag":"invalid-argument-value","analyzedSha":"1c9f0bb8013ed69c4f2efe11fd483025469b7e6c","analyzedAt":"2026-09-15T20:33:18.891Z","contentChangedAt":"2026-09-15T20:33:18.891Z","schemaVersion":2},"datasetVersion":"2026-09-23T02:17:17.105Z"}