Skip to content

Commit 46e773c

Browse files
committedMay 19, 2017
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: #13043 Refs: nodejs/node-gyp#1199 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Steven R Loomis <[email protected]>
1 parent 6f21671 commit 46e773c

File tree

5 files changed

+28
-14
lines changed

5 files changed

+28
-14
lines changed
 

‎src/node.cc

+5-2
Original file line numberDiff line numberDiff line change
@@ -4342,8 +4342,11 @@ void Init(int* argc,
43424342
// Initialize ICU.
43434343
// If icu_data_dir is empty here, it will load the 'minimal' data.
43444344
if (!i18n::InitializeICUDirectory(icu_data_dir)) {
4345-
FatalError(nullptr, "Could not initialize ICU "
4346-
"(check NODE_ICU_DATA or --icu-data-dir parameters)");
4345+
fprintf(stderr,
4346+
"%s: could not initialize ICU "
4347+
"(check NODE_ICU_DATA or --icu-data-dir parameters)",
4348+
argv[0]);
4349+
exit(9);
43474350
}
43484351
#endif
43494352

‎src/node_i18n.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include <unicode/utypes.h>
5656
#include <unicode/putil.h>
5757
#include <unicode/uchar.h>
58+
#include <unicode/uclean.h>
5859
#include <unicode/udata.h>
5960
#include <unicode/uidna.h>
6061
#include <unicode/ucnv.h>
@@ -418,19 +419,19 @@ void GetVersion(const FunctionCallbackInfo<Value>& args) {
418419
} // anonymous namespace
419420

420421
bool InitializeICUDirectory(const std::string& path) {
422+
UErrorCode status = U_ZERO_ERROR;
421423
if (path.empty()) {
422-
UErrorCode status = U_ZERO_ERROR;
423424
#ifdef NODE_HAVE_SMALL_ICU
424425
// install the 'small' data.
425426
udata_setCommonData(&SMALL_ICUDATA_ENTRY_POINT, &status);
426427
#else // !NODE_HAVE_SMALL_ICU
427428
// no small data, so nothing to do.
428429
#endif // !NODE_HAVE_SMALL_ICU
429-
return (status == U_ZERO_ERROR);
430430
} else {
431431
u_setDataDirectory(path.c_str());
432-
return true; // No error.
432+
u_init(&status);
433433
}
434+
return status == U_ZERO_ERROR;
434435
}
435436

436437
int32_t ToUnicode(MaybeStackBuffer<char>* buf,

‎test/parallel/test-cli-node-options.js

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ if (common.hasCrypto) {
5757
expect('--use-bundled-ca', 'B\n');
5858
expect('--openssl-config=_ossl_cfg', 'B\n');
5959
}
60-
expect('--icu-data-dir=_d', 'B\n');
6160

6261
// V8 options
6362
expect('--max_old_space_size=0', 'B\n');

‎test/parallel/test-icu-data-dir.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
require('../common');
3+
const assert = require('assert');
4+
const { spawnSync } = require('child_process');
5+
6+
const expected =
7+
'could not initialize ICU ' +
8+
'(check NODE_ICU_DATA or --icu-data-dir parameters)';
9+
10+
{
11+
const child = spawnSync(process.execPath, ['--icu-data-dir=/', '-e', '0']);
12+
assert(child.stderr.toString().includes(expected));
13+
}
14+
15+
{
16+
const env = { NODE_ICU_DATA: '/' };
17+
const child = spawnSync(process.execPath, ['-e', '0'], { env });
18+
assert(child.stderr.toString().includes(expected));
19+
}

‎test/parallel/test-intl-no-icu-data.js

-8
This file was deleted.

2 commit comments

Comments
 (2)

MylesBorins commented on Jul 17, 2017

@MylesBorins
Contributor

a PR-URL was not included in this commit

bnoordhuis commented on Jul 17, 2017

@bnoordhuis
MemberAuthor

It was #13053.

Please sign in to comment.