]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
find_legacy_keymap: extend variant match bonus again
authorAdam Williamson <awilliam@redhat.com>
Tue, 19 Sep 2023 23:06:26 +0000 (16:06 -0700)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 22 Sep 2023 06:07:12 +0000 (08:07 +0200)
If the column is "-" and the X context variant specifer only
contains commas, we should also give the match bonus. The variant
string is supposed to be a comma-separated list as long as the
list of layouts, so it's quite natural for consumers to be written
in such a way that they pass a string only containing commas if
there are multiple layouts and no variants. anaconda is a real
world case that does this.

Signed-off-by: Adam Williamson <awilliam@redhat.com>
src/locale/localed-util.c
src/locale/test-localed-util.c

index eba13a2ac3be4f18a096abbcc5cb4da026b34dc3..9b6949e14dc959727d58a70b59dfe542ceebbc00 100644 (file)
@@ -839,7 +839,7 @@ int find_legacy_keymap(const X11Context *xc, char **ret) {
                         if (isempty(xc->model) || streq_ptr(xc->model, a[2])) {
                                 matching++;
 
-                                if (streq_ptr(xc->variant, a[3]) || (isempty(xc->variant) && streq(a[3], "-"))) {
+                                if (streq_ptr(xc->variant, a[3]) || ((isempty(xc->variant) || streq_skip_trailing_chars(xc->variant, "", ",")) && streq(a[3], "-"))) {
                                         matching++;
 
                                         if (streq_ptr(xc->options, a[4]))
index f702ff29b092d87887c2e7c77781dc226d6642b1..e92c178a980b93e028a7ed0398622dd531249405 100644 (file)
@@ -185,6 +185,13 @@ TEST(x11_convert_to_vconsole) {
         assert_se(streq(vc.keymap, "bg_bds-utf8"));
         vc_context_clear(&vc);
 
+        /* same, but with variant specified as "," */
+        log_info("/* test with variant as ',', desired match second (bg,us:) */");
+        assert_se(free_and_strdup(&xc.variant, ",") >= 0);
+        assert_se(x11_convert_to_vconsole(&xc, &vc) >= 0);
+        assert_se(streq(vc.keymap, "bg_bds-utf8"));
+        vc_context_clear(&vc);
+
         log_info("/* test with old mapping (fr:latin9) */");
         assert_se(free_and_strdup(&xc.layout, "fr") >= 0);
         assert_se(free_and_strdup(&xc.variant, "latin9") >= 0);