Skip to content

fix(lexer): reject unknown and malformed string and char escapes - #3759

Merged
BaseMax merged 2 commits into
mainfrom
fix/lexer-escapes
Nov 21, 2026
Merged

BaseMax merged 2 commits into
mainfrom
fix/lexer-escapes

Conversation

@BaseMax

@BaseMax BaseMax commented Nov 21, 2026

Copy link
Copy Markdown
Member

An unknown escape silently dropped its backslash ("\d+\q" became "d+q"), \u with no digits produced a NUL byte, \u41 was accepted, \UFFFFFFFF and surrogates produced invalid UTF-8, and a non-ASCII \u in a char literal kept only its low byte.

Now E260 is reported with a fix-it (double the backslash): unknown escapes in strings, triple strings, guillemet strings and char literals; \x needs exactly two hex digits, \u four, \U eight; surrogates and values above 10FFFF are rejected; a \u escape above 7F in a one-byte char literal is rejected. Messages are in both i18n tables.

Checked that compiler, std, tests, examples, website samples and book listings use no rejected escape. Built with bootstrap.sh --stages 2 (stage 2 compiles compiler/main.salam); tests/*/errors pass (802 of 803, link_no_kind fa fails the same on main), check section and a few string, escape and regex tests pass.

@BaseMax
BaseMax requested a review from a team as a code owner November 21, 2026 12:47
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 1 minute.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a6edce56-4b33-4842-a7c8-f8db628087ff
Commits

Reviewing files that changed from the base of the PR and between f20cbb9 and 16e9f19.

Files ignored due to path filters: 2

  • tests/en/general/escape_edges.out is excluded by !**/*.out
  • tests/fa/general/guillemet_escape.out is excluded by !**/*.out
Files selected for processing: 10

  • SKILL.md
  • compiler/i18n.salam
  • compiler/lexer/lexer_escape.salam
  • compiler/lexer/lexer_string.salam
  • tests/en/errors/char_escape_errors.salam
  • tests/en/errors/escape_hex_digit_count.salam
  • tests/en/errors/escape_not_unicode_scalar.salam
  • tests/en/errors/escape_unknown_in_string.salam
  • tests/en/general/escape_edges.salam
  • tests/fa/general/guillemet_escape.salam
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor
sha=16e9f19ea553bc39301f4992ddab211e4fa08894

🤖 Salam AI review

Verdict: 🛠️ Changes needed before merging

commit 16e9f19 · 12 files · +218 −2 · model salam

Summary

This PR hardens lexer escape handling by rejecting unknown and malformed escapes in string, triple, guillemet, and char literals, reporting E260 with fix-it hints and adding EN/FA error/general tests. The core validation logic in the diff looks directionally right and covers many previously accepted bad cases. I cannot fully confirm correctness because the i18n.salam diff was not shown and some lexer behavior depends on code outside the visible diff.

What changed

The PR adds escape validation in compiler/lexer/lexer_escape.salam and wires it into string, guillemet, triple, char, and UTF-8 char scanning in compiler/lexer/lexer_string.salam. It rejects unknown escapes, enforces exact hex digit counts for \x/\u/\U, rejects surrogates and values above U+10FFFF, and rejects \u escapes above 0x7F in one-byte char literals. It also adds EN/FA tests and documents the rule in SKILL.md.

Review

  • compiler/i18n.salam (diff not visible): The PR description says both i18n tables were updated, but compiler/i18n.salam was listed as modified without a diff. I could not verify that the new E260 messages/keys exist in both language tables and match the formatted strings used by lexer_escape.salam. Please confirm the message keys/text are present and consistent.
  • compiler/lexer/lexer_string.salam, scan_utf8_char: Escape checking is added only when quote == 34 (check_escapes(..., ESC_IN_STRING)). If single-quoted Unicode char literals like u'\u0041' or malformed single-quoted forms go through this path, unknown/malformed escapes may bypass the new validation. Can you confirm whether single-quoted u'...' literals are fully covered by existing scanning/validation?
  • compiler/lexer/lexer_escape.salam, esc_check_hex: For \x escapes, the code validates digit count but does not apply the char-literal byte-range rule used for \u/\U (cp > 127 in a one-byte char). Is a byte char literal intended to accept \x80..\xFF? If not, the same E260 diagnostic should apply; if yes, a test would make that intent explicit.
  • compiler/lexer/lexer_escape.salam, fix-it staging: The unknown-escape fix inserts \\ only when not g_lx_probe. That looks reasonable, but I cannot verify the surrounding lexer/probe conventions from the diff alone.

Tests

The added tests cover unknown escapes, hex digit count errors, non-Unicode scalars, char-literal byte/range cases, valid escape edges, and FA guillemet escaping. Consider adding a case for single-quoted u'...' malformed escapes if that form is supported, and a \x80 char-literal case to lock down intended behavior.

Risks

The main risk is incomplete coverage for a literal form not exercised by the new tests, especially single-quoted Unicode char literals. Since the i18n diff is missing from the review input, there is also a small risk of missing or mismatched localized diagnostics.


⚠️ This review was written automatically by an AI and may contain mistakes. It is a helper for maintainers, not a replacement for a human review: check the code yourself before merging.

@BaseMax

BaseMax commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

On the review points: the i18n.salam diff is a single long line per table, both tables got the same ten messages appended at the same index. Single-quoted u'...' literals do not process escapes at all, so u'\q' and u'A' are already rejected as not exactly one codepoint (checked). '\x80' to '\xFF' are intended as byte values in a char literal.

@BaseMax
BaseMax merged commit aedbc41 into main Nov 21, 2026
15 checks passed
@BaseMax
BaseMax deleted the fix/lexer-escapes branch November 21, 2026 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant