Repository navigation
fix(lexer): reject unknown and malformed string and char escapes - #3759
Conversation
|
Warning Review limit reachedYou'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. View limit details
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. |
sha=16e9f19ea553bc39301f4992ddab211e4fa08894
🤖 Salam AI reviewVerdict: 🛠️ Changes needed before merging commit SummaryThis 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 changedThe PR adds escape validation in Review
TestsThe 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 RisksThe 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.
|
|
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. |
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.