Skip to content

src: check if --icu-data-dir= points to valid dir

Rodrigo Muino Tomonari requested to merge github/fork/bnoordhuis/fix13043 into master

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 46345b93 ("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 abort/test-abort-icu-data-dir.

Note that a bad path is now a fatal error, not a silent error. I could make node print a warning and fall back to the builtin i18n data (if #ifdef NODE_HAVE_SMALL_ICU) but I don't know if ICU supports initializing twice. It seems to works for me locally with the patch below, /cc @srl295.

diff --git a/src/node_i18n.cc b/src/node_i18n.cc
index 30394f3..e85e115 100644
--- a/src/node_i18n.cc
+++ b/src/node_i18n.cc
@@ -430,6 +430,12 @@ bool InitializeICUDirectory(const std::string& path) {
   } else {
     u_setDataDirectory(path.c_str());
     u_init(&status);
+#ifdef NODE_HAVE_SMALL_ICU
+    if (status != U_ZERO_ERROR) {
+      status = U_ZERO_ERROR;
+      udata_setCommonData(&SMALL_ICUDATA_ENTRY_POINT, &status);
+    }
+#endif  // !NODE_HAVE_SMALL_ICU
   }
   return status == U_ZERO_ERROR;
 }

Merge request reports

Loading