Skip to content

content/mojibake: false positive on valid uppercase Portuguese words ending in "Ã" #1617

Closed

Description

@fabiomsnunes

Version: 0.0.171 (packages/rules/src/content/mojibake.ts as of 8bcd9e1)

What happens: valid UTF-8 Portuguese text in uppercase, such as "MANHÃ", "IRMÃ" or "MAÇÃ" followed by a space, is reported as utf8-as-latin1 encoding corruption, with the sample "Ã ".

Repro: a page served as UTF-8 (<meta charset="utf-8">, Content-Type: text/html; charset=utf-8) with:

<p>Abrimos de MANHÃ e à tarde.</p>

squirrel audit <url> --offline --rule-include content reports content/mojibake ("2 encoding corruption occurrence(s) in visible text (utf8-as-latin1)", sample "Ã "). The same page with "manhã" in lowercase passes.

Cause: MOJIBAKE_SEQUENCES has "Ã " for "à", written with a regular space (0x20). The UTF-8 bytes of "à" (C3 A0) decoded as latin1/cp1252 give "Ã" + NO-BREAK SPACE (U+00A0), not a regular space. With 0x20 the sequence matches any word ending in "Ã" before a space, which is common in uppercase Portuguese (headings, buttons, opening hours).

Possible fix: match U+00A0 instead of the space. If NBSP is normalised to a space before the rule runs, skip the match when the character before "Ã" is an uppercase letter, so "MANHÃ " counts as valid text while "Ã " after a lowercase letter or at the start of a word still counts as corruption.

Triage

Confirmed on current main. packages/rules/src/content/mojibake.ts lists "Ã " (U+0020) as the mojibake form of "à" in MOJIBAKE_SEQUENCES. Real latin1 decoding of the UTF-8 bytes C3 A0 yields "Ã" plus U+00A0, so the regular-space entry matches any word ending in uppercase "Ã" before a space ("MANHÃ ", "IRMÃ ", "MAÇÃ ").

Acceptance Criteria

  • <p>Abrimos de MANHÃ e à tarde.</p> served as UTF-8 produces no content/mojibake finding
  • Text such as "IRMÃ " and "MAÇÃ " produces no finding
  • Genuine mojibake for "à" (à followed by U+00A0, e.g. "cafà ") is still reported
  • A regression test covers both the uppercase false positive and the genuine corruption case
  • The rule's docs page is updated if the matching behaviour is described there

Generated by Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugrulessize: S

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions