Skip to content

Commit 5966650

Browse files
srl295evanlucas
authored andcommitted
intl: Don't crash if v8BreakIterator not available
If the undocumented v8BreakIterator does not have data available, monkeypatch it to throw an error instead of crashing. Fixes: #3111 PR-URL: #4253 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 27c17ce commit 5966650

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

lib/internal/process.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,21 @@ function setupConfig(_source) {
117117
if (value === 'false') return false;
118118
return value;
119119
});
120+
const processConfig = process.binding('config');
121+
// Intl.v8BreakIterator() would crash w/ fatal error, so throw instead.
122+
if (processConfig.hasIntl &&
123+
processConfig.hasSmallICU &&
124+
Intl.hasOwnProperty('v8BreakIterator') &&
125+
!process.icu_data_dir) {
126+
const des = Object.getOwnPropertyDescriptor(Intl, 'v8BreakIterator');
127+
des.value = function v8BreakIterator() {
128+
throw new Error('v8BreakIterator: full ICU data not installed. ' +
129+
'See https://github.com/nodejs/node/wiki/Intl');
130+
};
131+
Object.defineProperty(Intl, 'v8BreakIterator', des);
132+
}
133+
// Don’t let icu_data_dir leak through.
134+
delete process.icu_data_dir;
120135
}
121136

122137

src/node.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2976,6 +2976,13 @@ void SetupProcessObject(Environment* env,
29762976
READONLY_PROPERTY(versions,
29772977
"icu",
29782978
OneByteString(env->isolate(), U_ICU_VERSION));
2979+
2980+
if (icu_data_dir != nullptr) {
2981+
// Did the user attempt (via env var or parameter) to set an ICU path?
2982+
READONLY_PROPERTY(process,
2983+
"icu_data_dir",
2984+
OneByteString(env->isolate(), icu_data_dir));
2985+
}
29792986
#endif
29802987

29812988
const char node_modules_version[] = NODE_STRINGIFY(NODE_MODULE_VERSION);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
require('../common');
3+
const assert = require('assert');
4+
5+
if (global.Intl === undefined || Intl.v8BreakIterator === undefined) {
6+
return console.log('1..0 # Skipped: no Intl');
7+
}
8+
9+
try {
10+
new Intl.v8BreakIterator();
11+
// May succeed if data is available - OK
12+
} catch (e) {
13+
// May throw this error if ICU data is not available - OK
14+
assert.throws(() => new Intl.v8BreakIterator(), /ICU data/);
15+
}

0 commit comments

Comments
 (0)