Zbigniew Jędrzejewski-Szmek a9b472
From 537c00c984910f417a2f2d4aad997f822060d4d1 Mon Sep 17 00:00:00 2001
Zbigniew Jędrzejewski-Szmek a9b472
From: Adam Williamson <awilliam@redhat.com>
Zbigniew Jędrzejewski-Szmek a9b472
Date: Tue, 19 Sep 2023 16:06:26 -0700
Zbigniew Jędrzejewski-Szmek a9b472
Subject: [PATCH] find_legacy_keymap: extend variant match bonus again
Zbigniew Jędrzejewski-Szmek a9b472
Zbigniew Jędrzejewski-Szmek a9b472
If the column is "-" and the X context variant specifer only
Zbigniew Jędrzejewski-Szmek a9b472
contains commas, we should also give the match bonus. The variant
Zbigniew Jędrzejewski-Szmek a9b472
string is supposed to be a comma-separated list as long as the
Zbigniew Jędrzejewski-Szmek a9b472
list of layouts, so it's quite natural for consumers to be written
Zbigniew Jędrzejewski-Szmek a9b472
in such a way that they pass a string only containing commas if
Zbigniew Jędrzejewski-Szmek a9b472
there are multiple layouts and no variants. anaconda is a real
Zbigniew Jędrzejewski-Szmek a9b472
world case that does this.
Zbigniew Jędrzejewski-Szmek a9b472
Zbigniew Jędrzejewski-Szmek a9b472
Signed-off-by: Adam Williamson <awilliam@redhat.com>
Zbigniew Jędrzejewski-Szmek a9b472
---
Zbigniew Jędrzejewski-Szmek a9b472
 src/locale/localed-util.c      | 2 +-
Zbigniew Jędrzejewski-Szmek a9b472
 src/locale/test-localed-util.c | 7 +++++++
Zbigniew Jędrzejewski-Szmek a9b472
 2 files changed, 8 insertions(+), 1 deletion(-)
Zbigniew Jędrzejewski-Szmek a9b472
Zbigniew Jędrzejewski-Szmek a9b472
diff --git a/src/locale/localed-util.c b/src/locale/localed-util.c
Zbigniew Jędrzejewski-Szmek a9b472
index eba13a2ac3..9b6949e14d 100644
Zbigniew Jędrzejewski-Szmek a9b472
--- a/src/locale/localed-util.c
Zbigniew Jędrzejewski-Szmek a9b472
+++ b/src/locale/localed-util.c
Zbigniew Jędrzejewski-Szmek a9b472
@@ -839,7 +839,7 @@ int find_legacy_keymap(const X11Context *xc, char **ret) {
Zbigniew Jędrzejewski-Szmek a9b472
                         if (isempty(xc->model) || streq_ptr(xc->model, a[2])) {
Zbigniew Jędrzejewski-Szmek a9b472
                                 matching++;
Zbigniew Jędrzejewski-Szmek a9b472
 
Zbigniew Jędrzejewski-Szmek a9b472
-                                if (streq_ptr(xc->variant, a[3]) || (isempty(xc->variant) && streq(a[3], "-"))) {
Zbigniew Jędrzejewski-Szmek a9b472
+                                if (streq_ptr(xc->variant, a[3]) || ((isempty(xc->variant) || streq_skip_trailing_chars(xc->variant, "", ",")) && streq(a[3], "-"))) {
Zbigniew Jędrzejewski-Szmek a9b472
                                         matching++;
Zbigniew Jędrzejewski-Szmek a9b472
 
Zbigniew Jędrzejewski-Szmek a9b472
                                         if (streq_ptr(xc->options, a[4]))
Zbigniew Jędrzejewski-Szmek a9b472
diff --git a/src/locale/test-localed-util.c b/src/locale/test-localed-util.c
Zbigniew Jędrzejewski-Szmek a9b472
index f702ff29b0..e92c178a98 100644
Zbigniew Jędrzejewski-Szmek a9b472
--- a/src/locale/test-localed-util.c
Zbigniew Jędrzejewski-Szmek a9b472
+++ b/src/locale/test-localed-util.c
Zbigniew Jędrzejewski-Szmek a9b472
@@ -185,6 +185,13 @@ TEST(x11_convert_to_vconsole) {
Zbigniew Jędrzejewski-Szmek a9b472
         assert_se(streq(vc.keymap, "bg_bds-utf8"));
Zbigniew Jędrzejewski-Szmek a9b472
         vc_context_clear(&vc);
Zbigniew Jędrzejewski-Szmek a9b472
 
Zbigniew Jędrzejewski-Szmek a9b472
+        /* same, but with variant specified as "," */
Zbigniew Jędrzejewski-Szmek a9b472
+        log_info("/* test with variant as ',', desired match second (bg,us:) */");
Zbigniew Jędrzejewski-Szmek a9b472
+        assert_se(free_and_strdup(&xc.variant, ",") >= 0);
Zbigniew Jędrzejewski-Szmek a9b472
+        assert_se(x11_convert_to_vconsole(&xc, &vc) >= 0);
Zbigniew Jędrzejewski-Szmek a9b472
+        assert_se(streq(vc.keymap, "bg_bds-utf8"));
Zbigniew Jędrzejewski-Szmek a9b472
+        vc_context_clear(&vc);
Zbigniew Jędrzejewski-Szmek a9b472
+
Zbigniew Jędrzejewski-Szmek a9b472
         log_info("/* test with old mapping (fr:latin9) */");
Zbigniew Jędrzejewski-Szmek a9b472
         assert_se(free_and_strdup(&xc.layout, "fr") >= 0);
Zbigniew Jędrzejewski-Szmek a9b472
         assert_se(free_and_strdup(&xc.variant, "latin9") >= 0);