src: check if --icu-data-dir= points to valid dir
Call uc_init() after u_setDataDirectory() to find out if the data directory is actually valid. This commit removes parallel/test-intl-no-icu-data, added in commit 46345b9 ("src: make --icu-data-dir= switch testable"). It no longer works now that an invalid --icu-data-dir= argument is rejected. Coverage is now provided by parallel/test-icu-data-dir. Fixes: https://github.com/nodejs/node/issues/13043 Refs: https://github.com/nodejs/node-gyp/issues/1199 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Steven R Loomis <srloomis@us.ibm.com>
This commit is contained in:
parent
6f216710eb
commit
46e773c5db
@ -4342,8 +4342,11 @@ void Init(int* argc,
|
|||||||
// Initialize ICU.
|
// Initialize ICU.
|
||||||
// If icu_data_dir is empty here, it will load the 'minimal' data.
|
// If icu_data_dir is empty here, it will load the 'minimal' data.
|
||||||
if (!i18n::InitializeICUDirectory(icu_data_dir)) {
|
if (!i18n::InitializeICUDirectory(icu_data_dir)) {
|
||||||
FatalError(nullptr, "Could not initialize ICU "
|
fprintf(stderr,
|
||||||
"(check NODE_ICU_DATA or --icu-data-dir parameters)");
|
"%s: could not initialize ICU "
|
||||||
|
"(check NODE_ICU_DATA or --icu-data-dir parameters)",
|
||||||
|
argv[0]);
|
||||||
|
exit(9);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@
|
|||||||
#include <unicode/utypes.h>
|
#include <unicode/utypes.h>
|
||||||
#include <unicode/putil.h>
|
#include <unicode/putil.h>
|
||||||
#include <unicode/uchar.h>
|
#include <unicode/uchar.h>
|
||||||
|
#include <unicode/uclean.h>
|
||||||
#include <unicode/udata.h>
|
#include <unicode/udata.h>
|
||||||
#include <unicode/uidna.h>
|
#include <unicode/uidna.h>
|
||||||
#include <unicode/ucnv.h>
|
#include <unicode/ucnv.h>
|
||||||
@ -418,19 +419,19 @@ void GetVersion(const FunctionCallbackInfo<Value>& args) {
|
|||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
bool InitializeICUDirectory(const std::string& path) {
|
bool InitializeICUDirectory(const std::string& path) {
|
||||||
|
UErrorCode status = U_ZERO_ERROR;
|
||||||
if (path.empty()) {
|
if (path.empty()) {
|
||||||
UErrorCode status = U_ZERO_ERROR;
|
|
||||||
#ifdef NODE_HAVE_SMALL_ICU
|
#ifdef NODE_HAVE_SMALL_ICU
|
||||||
// install the 'small' data.
|
// install the 'small' data.
|
||||||
udata_setCommonData(&SMALL_ICUDATA_ENTRY_POINT, &status);
|
udata_setCommonData(&SMALL_ICUDATA_ENTRY_POINT, &status);
|
||||||
#else // !NODE_HAVE_SMALL_ICU
|
#else // !NODE_HAVE_SMALL_ICU
|
||||||
// no small data, so nothing to do.
|
// no small data, so nothing to do.
|
||||||
#endif // !NODE_HAVE_SMALL_ICU
|
#endif // !NODE_HAVE_SMALL_ICU
|
||||||
return (status == U_ZERO_ERROR);
|
|
||||||
} else {
|
} else {
|
||||||
u_setDataDirectory(path.c_str());
|
u_setDataDirectory(path.c_str());
|
||||||
return true; // No error.
|
u_init(&status);
|
||||||
}
|
}
|
||||||
|
return status == U_ZERO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ToUnicode(MaybeStackBuffer<char>* buf,
|
int32_t ToUnicode(MaybeStackBuffer<char>* buf,
|
||||||
|
@ -57,7 +57,6 @@ if (common.hasCrypto) {
|
|||||||
expect('--use-bundled-ca', 'B\n');
|
expect('--use-bundled-ca', 'B\n');
|
||||||
expect('--openssl-config=_ossl_cfg', 'B\n');
|
expect('--openssl-config=_ossl_cfg', 'B\n');
|
||||||
}
|
}
|
||||||
expect('--icu-data-dir=_d', 'B\n');
|
|
||||||
|
|
||||||
// V8 options
|
// V8 options
|
||||||
expect('--max_old_space_size=0', 'B\n');
|
expect('--max_old_space_size=0', 'B\n');
|
||||||
|
19
test/parallel/test-icu-data-dir.js
Normal file
19
test/parallel/test-icu-data-dir.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
'use strict';
|
||||||
|
require('../common');
|
||||||
|
const assert = require('assert');
|
||||||
|
const { spawnSync } = require('child_process');
|
||||||
|
|
||||||
|
const expected =
|
||||||
|
'could not initialize ICU ' +
|
||||||
|
'(check NODE_ICU_DATA or --icu-data-dir parameters)';
|
||||||
|
|
||||||
|
{
|
||||||
|
const child = spawnSync(process.execPath, ['--icu-data-dir=/', '-e', '0']);
|
||||||
|
assert(child.stderr.toString().includes(expected));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const env = { NODE_ICU_DATA: '/' };
|
||||||
|
const child = spawnSync(process.execPath, ['-e', '0'], { env });
|
||||||
|
assert(child.stderr.toString().includes(expected));
|
||||||
|
}
|
@ -1,8 +0,0 @@
|
|||||||
// Flags: --icu-data-dir=test/fixtures/empty/
|
|
||||||
'use strict';
|
|
||||||
require('../common');
|
|
||||||
const assert = require('assert');
|
|
||||||
const config = process.binding('config');
|
|
||||||
|
|
||||||
assert.deepStrictEqual(Intl.NumberFormat.supportedLocalesOf('en'), []);
|
|
||||||
assert.strictEqual(config.icuDataDir, 'test/fixtures/empty/');
|
|
Loading…
x
Reference in New Issue
Block a user