From 8fc66a45d1311030511dc37ce9bc0fdb6913b3f7 Mon Sep 17 00:00:00 2001 From: Haris <4259838+Wulf@users.noreply.github.com> Date: Sat, 22 Nov 2025 08:32:54 -0500 Subject: [PATCH] Fix UTF16 test --- .github/workflows/Test.yml | 4 ++-- src/Async/AddDictionaryWorker.cc | 9 +++++---- src/Async/AddWithAffixWorker.cc | 2 +- src/Async/AddWorker.cc | 2 +- src/Async/AnalyzeWorker.cc | 2 +- src/Async/GenerateWorker.cc | 2 +- src/Async/RemoveWorker.cc | 2 +- src/Async/SpellWorker.cc | 2 +- src/Async/StemWorker.cc | 2 +- src/Async/SuggestWorker.cc | 2 +- src/Nodehun.cc | 9 +++++---- 11 files changed, 20 insertions(+), 18 deletions(-) diff --git a/.github/workflows/Test.yml b/.github/workflows/Test.yml index 3ad535b..7efe0c9 100644 --- a/.github/workflows/Test.yml +++ b/.github/workflows/Test.yml @@ -14,7 +14,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest] - node-version: ["lts/*", "node"] + node-version: ["lts/*"] steps: - name: Checkout code @@ -58,7 +58,7 @@ jobs: strategy: matrix: node-version: ["lts/*"] - arch: ["x64", "arm64"] + arch: ["x64"] include: - node-version: "22" arch: "x86" diff --git a/src/Async/AddDictionaryWorker.cc b/src/Async/AddDictionaryWorker.cc index eb142b8..9f1e80a 100644 --- a/src/Async/AddDictionaryWorker.cc +++ b/src/Async/AddDictionaryWorker.cc @@ -1,5 +1,6 @@ #include #include +#include #include "Worker.cc" class AddDictionaryWorker : public Worker { @@ -7,13 +8,13 @@ class AddDictionaryWorker : public Worker { AddDictionaryWorker( HunspellContext* context, Napi::Promise::Deferred d, - const char* dictionary) - : Worker(context, d), dictionary(dictionary) {} + std::string dictionary) + : Worker(context, d), dictionary(std::move(dictionary)) {} void Execute() { // Worker thread; don't use N-API here context->lockWrite(); - context->instance->add_dic(dictionary); + context->instance->add_dic(dictionary.c_str()); context->unlockWrite(); } @@ -24,5 +25,5 @@ class AddDictionaryWorker : public Worker { } private: - const char* dictionary; + std::string dictionary; }; \ No newline at end of file diff --git a/src/Async/AddWithAffixWorker.cc b/src/Async/AddWithAffixWorker.cc index 448f857..5809eb3 100644 --- a/src/Async/AddWithAffixWorker.cc +++ b/src/Async/AddWithAffixWorker.cc @@ -9,7 +9,7 @@ class AddWithAffixWorker : public Worker { Napi::Promise::Deferred d, std::string word, std::string example) - : Worker(context, d), word(word), example(example) {} + : Worker(context, d), word(std::move(word)), example(std::move(example)) {} void Execute() { // Worker thread; don't use N-API here diff --git a/src/Async/AddWorker.cc b/src/Async/AddWorker.cc index 582e397..5981635 100644 --- a/src/Async/AddWorker.cc +++ b/src/Async/AddWorker.cc @@ -8,7 +8,7 @@ class AddWorker : public Worker { HunspellContext* context, Napi::Promise::Deferred d, std::string word) - : Worker(context, d), word(word) {} + : Worker(context, d), word(std::move(word)) {} void Execute() { // Worker thread; don't use N-API here diff --git a/src/Async/AnalyzeWorker.cc b/src/Async/AnalyzeWorker.cc index 98dd9f7..22444bf 100644 --- a/src/Async/AnalyzeWorker.cc +++ b/src/Async/AnalyzeWorker.cc @@ -8,7 +8,7 @@ class AnalyzeWorker : public Worker { HunspellContext* context, Napi::Promise::Deferred d, std::string word) - : Worker(context, d), word(word) {} + : Worker(context, d), word(std::move(word)) {} void Execute() { // Worker thread; don't use N-API here diff --git a/src/Async/GenerateWorker.cc b/src/Async/GenerateWorker.cc index 3e6406c..4f1c2df 100644 --- a/src/Async/GenerateWorker.cc +++ b/src/Async/GenerateWorker.cc @@ -9,7 +9,7 @@ class GenerateWorker : public Worker { Napi::Promise::Deferred d, std::string word, std::string example) - : Worker(context, d), word(word), example(example) {} + : Worker(context, d), word(std::move(word)), example(std::move(example)) {} void Execute() { // Worker thread; don't use N-API here diff --git a/src/Async/RemoveWorker.cc b/src/Async/RemoveWorker.cc index 64836bb..128fa7d 100644 --- a/src/Async/RemoveWorker.cc +++ b/src/Async/RemoveWorker.cc @@ -8,7 +8,7 @@ class RemoveWorker : public Worker { HunspellContext* context, Napi::Promise::Deferred d, std::string word) - : Worker(context, d), word(word) {} + : Worker(context, d), word(std::move(word)) {} void Execute() { // Worker thread; don't use N-API here diff --git a/src/Async/SpellWorker.cc b/src/Async/SpellWorker.cc index ee81f09..9684cd4 100644 --- a/src/Async/SpellWorker.cc +++ b/src/Async/SpellWorker.cc @@ -8,7 +8,7 @@ class SpellWorker : public Worker { HunspellContext* context, Napi::Promise::Deferred d, std::string word) - : Worker(context, d), word(word) {} + : Worker(context, d), word(std::move(word)) {} void Execute() { // Worker thread; don't use N-API here diff --git a/src/Async/StemWorker.cc b/src/Async/StemWorker.cc index b0cd139..3fb815e 100644 --- a/src/Async/StemWorker.cc +++ b/src/Async/StemWorker.cc @@ -8,7 +8,7 @@ class StemWorker : public Worker { HunspellContext* context, Napi::Promise::Deferred d, std::string word) - : Worker(context, d), word(word) {} + : Worker(context, d), word(std::move(word)) {} void Execute() { // Worker thread; don't use N-API here diff --git a/src/Async/SuggestWorker.cc b/src/Async/SuggestWorker.cc index 2073940..b107ac4 100644 --- a/src/Async/SuggestWorker.cc +++ b/src/Async/SuggestWorker.cc @@ -8,7 +8,7 @@ class SuggestWorker : public Worker { HunspellContext* context, Napi::Promise::Deferred d, std::string word) - : Worker(context, d), word(word) {} + : Worker(context, d), word(std::move(word)) {} void Execute() { // Worker thread; don't use N-API here diff --git a/src/Nodehun.cc b/src/Nodehun.cc index f97510b..e1a841a 100644 --- a/src/Nodehun.cc +++ b/src/Nodehun.cc @@ -111,8 +111,9 @@ Napi::Value Nodehun::addDictionarySync(const Napi::CallbackInfo& info) { return error.Value(); } else { Napi::Buffer dictionaryBuffer = info[0].As>(); - - context->instance->add_dic(dictionaryBuffer.Data()); + + std::string dictionary(dictionaryBuffer.Data(), dictionaryBuffer.Length()); + context->instance->add_dic(dictionary.c_str()); return env.Undefined(); } @@ -135,7 +136,7 @@ Napi::Value Nodehun::addDictionary(const Napi::CallbackInfo& info) { AddDictionaryWorker* worker = new AddDictionaryWorker( context, deferred, - dictionaryBuffer.Data() + std::string(dictionaryBuffer.Data(), dictionaryBuffer.Length()) ); worker->Queue(); @@ -654,7 +655,7 @@ Napi::Value Nodehun::getWordCharactersUTF16(const Napi::CallbackInfo& info) { if (chars == NULL) { return env.Undefined(); } else { - return Napi::String::New(env, ((char16_t*) chars)); + return Napi::String::New(env, ((char16_t*) chars), (size_t)length); } }