chiark / gitweb /
documentation: provide autocompletion in UTF-8 as well.
authorVladimír Vondruš <mosra@centrum.cz>
Thu, 18 Jul 2019 15:21:01 +0000 (17:21 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Thu, 18 Jul 2019 15:48:56 +0000 (17:48 +0200)
The search() function returns the result list in UTF-8, but the
autocompletion was not. And of course renderResults() assumed it was in
UTF-8 and decoded it from UTF-8 *twice*. This wasn't discovered until
now because I had no pages with UTF-8 names apart from the test (which
doesn't test the UI stuff).

documentation/search.js
documentation/test/test-search.js

index d1a938784c81ee25b04f4166b0078b998086e563..9b94a3c9ddc02e3bc8d023d0f886ca7a64169691 100644 (file)
@@ -194,7 +194,7 @@ var Search = {
     toUtf8: function(string) { return unescape(encodeURIComponent(string)); },
     fromUtf8: function(string) { return decodeURIComponent(escape(string)); },
 
-    autocompletedCharsToString: function(chars) {
+    autocompletedCharsToUtf8: function(chars) {
         /* Strip incomplete UTF-8 chars from the autocompletion end */
         for(let i = chars.length - 1; i >= 0; --i) {
             let c = chars[i];
@@ -226,7 +226,7 @@ var Search = {
         let suggestedTabAutocompletionString = '';
         for(let i = 0; i != chars.length; ++i)
             suggestedTabAutocompletionString += String.fromCharCode(chars[i]);
-        return this.fromUtf8(suggestedTabAutocompletionString);
+        return suggestedTabAutocompletionString;
     },
 
     /* Returns the values in UTF-8, but input is in whatever shitty 16bit
@@ -323,7 +323,7 @@ var Search = {
 
                 /* 'nuff said. */
                 if(results.length >= this.maxResults)
-                    return [results, this.autocompletedCharsToString(suggestedTabAutocompletionChars)];
+                    return [results, this.autocompletedCharsToUtf8(suggestedTabAutocompletionChars)];
             }
 
             /* Dig deeper */
@@ -352,7 +352,7 @@ var Search = {
             }
         }
 
-        return [results, this.autocompletedCharsToString(suggestedTabAutocompletionChars)];
+        return [results, this.autocompletedCharsToUtf8(suggestedTabAutocompletionChars)];
     },
 
     gatherResult: function(index, suffixLength, maxUrlPrefix) {
index 9e8fb60d6df43705a6415d0efba4253fd1340eea..ec45d2189d99dde5a068eb40de8f4bbe7dbb1f58 100644 (file)
@@ -304,14 +304,14 @@ const { StringDecoder } = require('string_decoder');
           flags: 0,
           cssClass: 'm-success',
           typeName: 'page',
-          suffixLength: 5 }], 'ždě']);
+          suffixLength: 5 }], Search.toUtf8('ždě')]);
     assert.deepEqual(Search.search('há'), [[
         { name: Search.toUtf8('Hárá'),
           url: '#b',
           flags: 0,
           cssClass: 'm-success',
           typeName: 'page',
-          suffixLength: 3 }], 'rá']);
+          suffixLength: 3 }], Search.toUtf8('rá')]);
 }
 
 /* Properly combine heavily nested URLs */