Skip to content

Commit 728d233

Browse files
committed
fix(workflow-code): treat word joiners, the BOM and other invisible format characters as suspicious
The printer escapes and compile warns through one definition, which missed U+061C, U+180E, U+2060-U+2064, U+206A-U+206F and U+FEFF.
1 parent e3367b4 commit 728d233

3 files changed

Lines changed: 26 additions & 4 deletions

File tree

‎packages/workflow-code/src/compile/ergonomics.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,22 @@ describe('header, names and hand-written references', () => {
229229
expect(quoteString('Pay\u202Eout\u200B')).toBe("'Pay\\u202Eout\\u200B'")
230230
})
231231

232+
it.each([
233+
['an Arabic letter mark', 0x061c],
234+
['a Mongolian vowel separator', 0x180e],
235+
['a word joiner', 0x2060],
236+
['an invisible plus', 0x2064],
237+
['a deprecated shaping control', 0x206f],
238+
['a zero-width no-break space', 0xfeff],
239+
])('treats %s as invisible in names and printed text', (_, code) => {
240+
const char = String.fromCharCode(code)
241+
const escaped = `\\u${code.toString(16).toUpperCase().padStart(4, '0')}`
242+
expect(codes(run(source(` api('Pay${escaped}out', { url: 'x' })`)))).toEqual([
243+
'W_SUSPICIOUS_CHARACTER',
244+
])
245+
expect(quoteString(`Pay${char}out`)).toBe(`'Pay${escaped}out'`)
246+
})
247+
232248
it.each([
233249
['a cased block name', "'<A.data>'", true],
234250
['a name that is no block', "'<nobody.data>'", true],

‎packages/workflow-code/src/diagnostics/codes.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type CompileScopeCode =
5858
| 'E_KEY_OVERRIDE'
5959
/** A block's display name is the empty string. */
6060
| 'E_EMPTY_NAME'
61-
/** A block name holds a bidi control or zero-width character (`isSuspiciousCharacter`). */
61+
/** A block name holds an invisible or bidi control character (`isSuspiciousCharacter`). */
6262
| 'W_SUSPICIOUS_CHARACTER'
6363
/** A block or workflow name that is not a string literal. */
6464
| 'E_NAME_NOT_LITERAL'

‎packages/workflow-code/src/print/strings.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,20 @@
99
import { isIdentifierName } from '../code-files/ref-path'
1010

1111
/**
12-
* Bidi embedding and isolate controls (U+202A–U+202E, U+2066–U+2069) and zero-width characters
13-
* (U+200B–U+200F): invisible, they make printed text read differently from what it stores.
12+
* Characters that reorder or hide text without a glyph of their own: bidi marks, embeddings and
13+
* isolates (U+061C, U+200E–U+200F, U+202A–U+202E, U+2066–U+2069), zero-width and invisible
14+
* characters (U+180E, U+200B–U+200D, U+2060–U+2064, U+FEFF) and the deprecated format controls
15+
* (U+206A–U+206F). The printer escapes them and compile warns on a block name holding one, so
16+
* printed text never reads differently from what it stores.
1417
*/
1518
export function isSuspiciousCharacter(code: number): boolean {
1619
return (
20+
code === 0x061c ||
21+
code === 0x180e ||
1722
(code >= 0x200b && code <= 0x200f) ||
1823
(code >= 0x202a && code <= 0x202e) ||
19-
(code >= 0x2066 && code <= 0x2069)
24+
(code >= 0x2060 && code <= 0x206f) ||
25+
code === 0xfeff
2026
)
2127
}
2228

0 commit comments

Comments
 (0)