Skip to content

Commit a96c86a

Browse files
authored
fix(blessed): use hex escapes for Node 24 strict-mode compatibility (#1396)
Node 24 rejects octal escape sequences in strict mode, so the vendored blessed lib/tput.js ('\200', '\016', '\017') threw a SyntaxError on startup and the CLI could not run on Node 24. Extend the blessed patch to use the byte-equivalent hex escapes ('\x80', '\x0e', '\x0f').
1 parent 8315488 commit a96c86a

3 files changed

Lines changed: 49 additions & 4 deletions

File tree

patches/blessed@0.1.81.patch

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ index 0b1e56fadcf60719ca2e5231447ad2f8ace44bda..1494b715fb8f2143505bb2b5cea053d8
5252

5353
Program.prototype.bel =
5454
diff --git a/lib/tput.js b/lib/tput.js
55-
index 2a57f58b08e797e9751983eef917c127481770d5..aec81d28014cd7b9527d114dd0e9530acf1535ab 100644
55+
index 2a57f58b08e797e9751983eef917c127481770d5..ddfb9b88f64829ac0db9da4a200d874a7a88b0bc 100644
5656
--- a/lib/tput.js
5757
+++ b/lib/tput.js
5858
@@ -366,7 +366,7 @@ Tput.prototype.parseTerminfo = function(data, file) {
@@ -91,6 +91,15 @@ index 2a57f58b08e797e9751983eef917c127481770d5..aec81d28014cd7b9527d114dd0e9530a
9191
_strings.push(-1);
9292
} else {
9393
_strings.push((data[i + 1] << 8) | data[i]);
94+
@@ -884,7 +884,7 @@ Tput.prototype._compile = function(info, key, str) {
95+
ch = ':';
96+
break;
97+
case '0':
98+
- ch = '\200';
99+
+ ch = '\x80';
100+
break;
101+
case 'a':
102+
ch = '\x07';
94103
@@ -926,7 +926,7 @@ Tput.prototype._compile = function(info, key, str) {
95104
echo('sprintf("'+ cap[0].replace(':-', '-') + '", stack.pop())');
96105
} else if (cap[3] === 'c') {
@@ -100,6 +109,21 @@ index 2a57f58b08e797e9751983eef917c127481770d5..aec81d28014cd7b9527d114dd0e9530a
100109
} else {
101110
echo('stack.pop()');
102111
}
112+
@@ -2094,10 +2094,10 @@ Tput.prototype.detectBrokenACS = function(info) {
113+
&& process.env.TERMCAP
114+
&& ~process.env.TERMCAP.indexOf('screen')
115+
&& ~process.env.TERMCAP.indexOf('hhII00')) {
116+
- if (~info.strings.enter_alt_charset_mode.indexOf('\016')
117+
- || ~info.strings.enter_alt_charset_mode.indexOf('\017')
118+
- || ~info.strings.set_attributes.indexOf('\016')
119+
- || ~info.strings.set_attributes.indexOf('\017')) {
120+
+ if (~info.strings.enter_alt_charset_mode.indexOf('\x0e')
121+
+ || ~info.strings.enter_alt_charset_mode.indexOf('\x0f')
122+
+ || ~info.strings.set_attributes.indexOf('\x0e')
123+
+ || ~info.strings.set_attributes.indexOf('\x0f')) {
124+
return true;
125+
}
126+
}
103127
@@ -2276,7 +2276,7 @@ function sprintf(src) {
104128
break;
105129
case 'c': // char

pnpm-lock.yaml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { readFileSync } from 'node:fs'
2+
import { createRequire } from 'node:module'
3+
4+
import { describe, expect, it } from 'vitest'
5+
6+
const require = createRequire(import.meta.url)
7+
8+
// Regression for Node 24 compatibility: blessed's lib/tput.js used octal escape
9+
// sequences ('\200', '\016', '\017') that throw "Octal escape sequences are not
10+
// allowed in strict mode" when the CLI's strict/bundled output loads it, so the
11+
// CLI crashed on startup under Node 24. The blessed pnpm patch rewrites them as
12+
// hex escapes. This guards that the shipped tput.js stays strict-mode-safe.
13+
describe('blessed Node 24 compatibility', () => {
14+
it('lib/tput.js parses under strict mode', () => {
15+
const source = readFileSync(require.resolve('blessed/lib/tput.js'), 'utf8')
16+
// Compiles (does not execute) the module in strict mode via the Function
17+
// constructor, surfacing octal-escape syntax errors the same way Node 24
18+
// does at load time.
19+
expect(() => Function(`"use strict";\n${source}`)).not.toThrow()
20+
})
21+
})

0 commit comments

Comments
 (0)