Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: do not read a private field or Unicode name as a regex keyword (#7945)

[._.]/ Adam Eivyba57dfcc4903
diff --git a/server/lib/sourceScan.js b/server/lib/sourceScan.js
index d5ef8d5511..c32757e129 100644
--- a/server/lib/sourceScan.js
+++ b/server/lib/sourceScan.js
@@ -54,17 +54,24 @@ const KEYWORDS_BEFORE_REGEX = new Set([
'instanceof', 'new', 'return', 'throw', 'typeof', 'void', 'yield',
]);
+// Anything that can appear inside an identifier, Unicode included: `café`
+// ends in `e`, and an ASCII-only boundary would read `naïvereturn` as ending
+// in the keyword `return`.
+const IDENTIFIER_CHAR = /[\p{ID_Continue}$]/u;
+
/**
* The identifier ending at `end` (exclusive) in the character ARRAY `chars`, or
- * '' when the preceding character is not an identifier character. Reads the
- * PARTIALLY BLANKED output, so a keyword spelled inside an already-blanked
- * string or comment is invisible here — which is the point.
+ * '' when what ends there is not a bare identifier. Reads the PARTIALLY
+ * BLANKED output, so a keyword spelled inside an already-blanked string or
+ * comment is invisible here — which is the point.
*/
function wordEndingAt(chars, end) {
let start = end;
- while (start > 0 && /[A-Za-z0-9_$]/.test(chars[start - 1])) start -= 1;
- // `obj.in` / `obj.return` are property reads, not keywords.
- if (start > 0 && chars[start - 1] === '.') return '';
+ while (start > 0 && IDENTIFIER_CHAR.test(chars[start - 1])) start -= 1;
+ // `obj.return` is a property read and `this.#return` a private field: both
+ // are VALUES, so a `/` after one divides. Reading either as the keyword lexes
+ // that division as a regex opener and blanks the rest of the line.
+ if (start > 0 && (chars[start - 1] === '.' || chars[start - 1] === '#')) return '';
return chars.slice(start, end).join('');
}
@@ -75,7 +82,7 @@ function wordEndingAt(chars, end) {
*/
function regexCanStartAfter(prev, chars, at) {
if (prev === '' || '(,=:[!&|?{};+-*%~^<>'.includes(prev)) return true;
- if (!/[A-Za-z0-9_$]/.test(prev)) return false;
+ if (!IDENTIFIER_CHAR.test(prev)) return false;
// Step back over the whitespace between the keyword and the `/`.
let end = at;
while (end > 0 && /\s/.test(chars[end - 1])) end -= 1;
diff --git a/server/logLevelConventions.test.js b/server/logLevelConventions.test.js
index aa83e193a7..4f42aacdbd 100644
--- a/server/logLevelConventions.test.js
+++ b/server/logLevelConventions.test.js
@@ -274,6 +274,18 @@ describe('the failure-log recognizer', () => {
expect(findMislabeledFailureLogs(
`console.log(limits.in / (count), \`${CROSS_MARK} failed\`);`,
)).toHaveLength(1);
+ // Same for a private field — `#return` is a name, not the keyword.
+ expect(findMislabeledFailureLogs(
+ `class C { #return = 4; m(n) { console.log(this.#return / (n), \`${CROSS_MARK} failed\`); } }`,
+ )).toHaveLength(1);
+ // And for an identifier that merely ENDS in a keyword's letters, including
+ // one with a non-ASCII character an ASCII-only boundary would split on.
+ expect(findMislabeledFailureLogs(
+ `console.log(caseCount / (n), \`${CROSS_MARK} failed\`);`,
+ )).toHaveLength(1);
+ expect(findMislabeledFailureLogs(
+ `console.log(café / (n), \`${CROSS_MARK} failed\`);`,
+ )).toHaveLength(1);
});
// Bypass probe: the scan is only worth its runtime if a reintroduced