From 18c6ecfc088e4044affa313b3c3062c9a3f040ca Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Mon, 25 Mar 2024 16:45:01 -0500 Subject: [PATCH] =?UTF-8?q?fix(core):=20fix=202=20marker=20cases=20in=20ld?= =?UTF-8?q?ml=5Fevent=5Fstate::emit=5Fdifference=20=F0=9F=99=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - handle the case where old and new context strings are the same (i.e. no work to do). - fix pointer arithmetic error in #10356 - the special case where one marker is being replaced by another. The named regression test didn't actually hit this case. Fixes: bug(core): 'string too long' #11057 --- core/src/ldml/ldml_processor.cpp | 10 +- .../keyboards/k_212_marker_11057-test.xml | 23 ++ .../ldml/keyboards/k_212_marker_11057.xml | 30 +++ .../ldml/keyboards/k_213_marker_11057.xml | 225 ++++++++++++++++++ core/tests/unit/ldml/keyboards/meson.build | 5 +- 5 files changed, 288 insertions(+), 5 deletions(-) create mode 100644 core/tests/unit/ldml/keyboards/k_212_marker_11057-test.xml create mode 100644 core/tests/unit/ldml/keyboards/k_212_marker_11057.xml create mode 100644 core/tests/unit/ldml/keyboards/k_213_marker_11057.xml diff --git a/core/src/ldml/ldml_processor.cpp b/core/src/ldml/ldml_processor.cpp index 166b8002b8..5ec0b900d5 100644 --- a/core/src/ldml/ldml_processor.cpp +++ b/core/src/ldml/ldml_processor.cpp @@ -377,6 +377,10 @@ ldml_event_state::emit_difference(const std::u32string &old_ctxt, const std::u32 // So the BBBBB needs to be removed and then CCC added. auto ctxt_prefix = mismatch(old_ctxt.begin(), old_ctxt.end(), new_ctxt.begin(), new_ctxt.end()); + if(ctxt_prefix.first == old_ctxt.end() && ctxt_prefix.second == new_ctxt.end()) { + return; // No mismatch. We can just exit, there's nothing to do. + } + // handle a special case where we're simply changing from one marker to another. // Example: // 0. old_ctxtstr_changed ends with … U+FFFF U+0008 | U+0001 … @@ -390,14 +394,14 @@ ldml_event_state::emit_difference(const std::u32string &old_ctxt, const std::u32 // marker change. // We can detect this because the unchanged_prefix will end with u+FFFF U+0008 // - // Oh, and yes, test case 'regex-test-8a-0' hits this. + // k_212* and k_213* hit this case. std::u32string common_prefix(old_ctxt.begin(), ctxt_prefix.first); if (common_prefix.length() >= 2) { auto iter = common_prefix.rbegin(); if (*(iter++) == LDML_MARKER_CODE && *(iter++) == UC_SENTINEL) { // adjust the iterator so that the "U+FFFF U+0008" is not a part of the common prefix. - ctxt_prefix.first -= 2; - ctxt_prefix.second += 2; + ctxt_prefix.first -= 2; // backup the 'mismatch' point to before the FFFF + ctxt_prefix.second -= 2; // backup the 'mismatch' point to before the FFFF // Now, old_ctxtstr_changed and new_ctxtstr_changed will start with U+FFFF U+0008 … } } diff --git a/core/tests/unit/ldml/keyboards/k_212_marker_11057-test.xml b/core/tests/unit/ldml/keyboards/k_212_marker_11057-test.xml new file mode 100644 index 0000000000..92e2abbf3f --- /dev/null +++ b/core/tests/unit/ldml/keyboards/k_212_marker_11057-test.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/tests/unit/ldml/keyboards/k_212_marker_11057.xml b/core/tests/unit/ldml/keyboards/k_212_marker_11057.xml new file mode 100644 index 0000000000..7bbd2bb94a --- /dev/null +++ b/core/tests/unit/ldml/keyboards/k_212_marker_11057.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/tests/unit/ldml/keyboards/k_213_marker_11057.xml b/core/tests/unit/ldml/keyboards/k_213_marker_11057.xml new file mode 100644 index 0000000000..f137e8d2a4 --- /dev/null +++ b/core/tests/unit/ldml/keyboards/k_213_marker_11057.xml @@ -0,0 +1,225 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/tests/unit/ldml/keyboards/meson.build b/core/tests/unit/ldml/keyboards/meson.build index ca047a67bc..4e0b35803b 100644 --- a/core/tests/unit/ldml/keyboards/meson.build +++ b/core/tests/unit/ldml/keyboards/meson.build @@ -28,10 +28,10 @@ tests_without_testdata = [ 'k_100_keytest', 'k_101_keytest', 'k_102_keytest', - + 'k_213_marker_11057', ] -# These tests have a k_001_tiny-test.xml file as well. +# These tests have a *-test.xml file as well. tests_with_testdata = [ 'ldml_test', 'k_001_tiny', @@ -44,6 +44,7 @@ tests_with_testdata = [ 'k_201_reorder_esk', 'k_210_marker', 'k_211_marker_escape', + 'k_212_marker_11057', ] tests = tests_without_testdata