detached 5f59a46

fix(expr): unescape every doubled quote in string literals, as the runner does

commit
5f59a46a3ed5e3f88477bf109ad55f8ffaec5471
author
brice · · 2026-10-12 17:28 UTC
parent
f5fe276
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
3 files · +19 -14
M expr/PORTING.md +8 -5
@@ -64,11 +64,14 @@ Each item is implemented as the JavaScript does. Check the runner's tests
6464 (`src/Test/L0/Expressions*`, `Sdk/Expressions2/...`) and decide for each one
6565 whether to keep the JS behaviour or follow the runner.
6666
67-- [ ] **String escapes: only the first `''` is unescaped.** The lexer does
68- `value.replace("''", "'")` with a string pattern, which replaces one
69- occurrence: `'a''b''c'` is `a'b''c`. The C# lexer should unescape every
70- pair (`StringBuilder`/`Replace`). Probable JS bug. (`lexer.go`,
71- `consumeString`; tests: `TestEvalLiteralsAndOperators`.)
67+- [x] **String escapes: every `''` is unescaped.** Resolved: follows the C#.
68+ `LexicalAnalyzer.ReadStringToken` (`Tokens/LexicalAnalyzer.cs`, the
69+ "Escaped single quote" branch) skips the second quote of each pair and
70+ appends the first, so `'a''b''c'` is `a'b'c`. The JavaScript lexer does
71+ `value.replace("''", "'")` (first pair only) and gives `a'b''c`; that is
72+ a bug of the editor library. Tests: `TestEvalLiteralsAndOperators`; the
73+ oracle excuses the JS mismatch because `testdata/runner.json.gz` agrees
74+ with this package.
7275 - [ ] **`case()` availability.** The JS gates it behind the experimental flag
7376 `allowCaseFunction`, but only in completion; the parser and the
7477 evaluator always accept it. Here it is always on. Confirm whether the
@@ -64,11 +64,14 @@ Each item is implemented as the JavaScript does. Check the runner's tests
64 (`src/Test/L0/Expressions*`, `Sdk/Expressions2/...`) and decide for each one64 (`src/Test/L0/Expressions*`, `Sdk/Expressions2/...`) and decide for each one
65 whether to keep the JS behaviour or follow the runner.65 whether to keep the JS behaviour or follow the runner.
66 66
67-- [ ] **String escapes: only the first `''` is unescaped.** The lexer does67+- [x] **String escapes: every `''` is unescaped.** Resolved: follows the C#.
68- `value.replace("''", "'")` with a string pattern, which replaces one68+ `LexicalAnalyzer.ReadStringToken` (`Tokens/LexicalAnalyzer.cs`, the
69- occurrence: `'a''b''c'` is `a'b''c`. The C# lexer should unescape every69+ "Escaped single quote" branch) skips the second quote of each pair and
70- pair (`StringBuilder`/`Replace`). Probable JS bug. (`lexer.go`,70+ appends the first, so `'a''b''c'` is `a'b'c`. The JavaScript lexer does
71- `consumeString`; tests: `TestEvalLiteralsAndOperators`.)71+ `value.replace("''", "'")` (first pair only) and gives `a'b''c`; that is
72+ a bug of the editor library. Tests: `TestEvalLiteralsAndOperators`; the
73+ oracle excuses the JS mismatch because `testdata/runner.json.gz` agrees
74+ with this package.
72 - [ ] **`case()` availability.** The JS gates it behind the experimental flag75 - [ ] **`case()` availability.** The JS gates it behind the experimental flag
73 `allowCaseFunction`, but only in completion; the parser and the76 `allowCaseFunction`, but only in completion; the parser and the
74 evaluator always accept it. Here it is always on. Confirm whether the77 evaluator always accept it. Here it is always on. Confirm whether the
M expr/eval_test.go +4 -4
@@ -88,11 +88,11 @@ func TestEvalLiteralsAndOperators(t *testing.T) {
8888 {"'a'", "String:a"},
8989 {"''", "String:"},
9090 {"'it''s'", "String:it's"},
91- // Only the first doubled quote is unescaped: the reference's
92- // value.replace("''", "'") is not global.
93- {"'a''b''c'", "String:a'b''c"},
91+ // Every doubled quote is unescaped, as the C# runner does (the
92+ // JavaScript reference stops after the first).
93+ {"'a''b''c'", "String:a'b'c"},
9494 {"''''", "String:'"},
95- {"'a''''b'", "String:a'''b"},
95+ {"'a''''b'", "String:a''b"},
9696
9797 {"1 == 1", "Boolean:true"},
9898 {"1 == 2", "Boolean:false"},
@@ -88,11 +88,11 @@ func TestEvalLiteralsAndOperators(t *testing.T) {
88 {"'a'", "String:a"},88 {"'a'", "String:a"},
89 {"''", "String:"},89 {"''", "String:"},
90 {"'it''s'", "String:it's"},90 {"'it''s'", "String:it's"},
91- // Only the first doubled quote is unescaped: the reference's91+ // Every doubled quote is unescaped, as the C# runner does (the
92- // value.replace("''", "'") is not global.92+ // JavaScript reference stops after the first).
93- {"'a''b''c'", "String:a'b''c"},93+ {"'a''b''c'", "String:a'b'c"},
94 {"''''", "String:'"},94 {"''''", "String:'"},
95- {"'a''''b'", "String:a'''b"},95+ {"'a''''b'", "String:a''b"},
96 96
97 {"1 == 1", "Boolean:true"},97 {"1 == 1", "Boolean:true"},
98 {"1 == 2", "Boolean:false"},98 {"1 == 2", "Boolean:false"},
M expr/lexer.go +7 -5
@@ -295,11 +295,13 @@ func (l *lexer) consumeString() error {
295295 }
296296 l.next() // closing quote
297297 value := l.substring(l.start+1, l.offset-1)
298- // The reference calls value.replace("''", "'") with a string pattern,
299- // which replaces only the FIRST doubled quote: 'a''b''c' is a'b''c.
300- // GitHub's C# lexer unescapes every pair. Followed as written; see
301- // PORTING.md.
302- value = strings.Replace(value, "''", "'", 1)
298+ // Every doubled quote is one quote. The JavaScript reference calls
299+ // value.replace("''", "'") with a string pattern, which replaces only the
300+ // first pair ('a''b''c' is a'b''c there); the C# runner, which is what
301+ // runs on github.com, appends one quote per pair
302+ // (Tokens/LexicalAnalyzer.cs ReadStringToken, "Escaped single quote"), and
303+ // this package follows it. See PORTING.md.
304+ value = strings.ReplaceAll(value, "''", "'")
303305 l.addToken(TokenString, String(value))
304306 return nil
305307 }
@@ -295,11 +295,13 @@ func (l *lexer) consumeString() error {
295 }295 }
296 l.next() // closing quote296 l.next() // closing quote
297 value := l.substring(l.start+1, l.offset-1)297 value := l.substring(l.start+1, l.offset-1)
298- // The reference calls value.replace("''", "'") with a string pattern,298+ // Every doubled quote is one quote. The JavaScript reference calls
299- // which replaces only the FIRST doubled quote: 'a''b''c' is a'b''c.299+ // value.replace("''", "'") with a string pattern, which replaces only the
300- // GitHub's C# lexer unescapes every pair. Followed as written; see300+ // first pair ('a''b''c' is a'b''c there); the C# runner, which is what
301- // PORTING.md.301+ // runs on github.com, appends one quote per pair
302- value = strings.Replace(value, "''", "'", 1)302+ // (Tokens/LexicalAnalyzer.cs ReadStringToken, "Escaped single quote"), and
303+ // this package follows it. See PORTING.md.
304+ value = strings.ReplaceAll(value, "''", "'")
303 l.addToken(TokenString, String(value))305 l.addToken(TokenString, String(value))
304 return nil306 return nil
305 }307 }

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 3

↑↓ moveenter openesc close