brave / brave-browser

Brave browser for Android, iOS, Linux, macOS, Windows.
https://brave.com
Mozilla Public License 2.0
17.84k stars 2.33k forks source link

Ignore Contiguous Whitespace in Sync Codes #16175

Open jonathansampson opened 3 years ago

jonathansampson commented 3 years ago

Description

Brave now trims sync code strings of leading and trailing whitespace. However, Brave still expects a single space between each word.

computeSyncCodeWordCount_: function() {
    if (!this.syncCode) {
        return 0
    }
    return this.syncCode.trim().split(' ').length
},

Instead, Brave should permit contiguous whitespace (such as multiple spaces and/or new lines) between words.

Actual result:

The following is not counted as 4 words:

foo bar
fizz     buzz

Desktop Brave version:

v1.25.68

Other Additional Information:

Related to #13681 and #10860.

Reported on Twitter by AJ ONeal.

coolaj86 commented 3 years ago

I was thinking maybe I'd do a little

diff --git a/browser/resources/settings/brave_sync_page/brave_sync_code_dialog.js b/browser/resources/settings/brave_sync_page/brave_sync_code_dialog.js
index 78e2091a7f..04d22124cc 100644
--- a/browser/resources/settings/brave_sync_page/brave_sync_code_dialog.js
+++ b/browser/resources/settings/brave_sync_page/brave_sync_code_dialog.js
@@ -83,7 +83,7 @@ Polymer({
     if (!this.syncCode) {
       return 0
     }
-    return this.syncCode.trim().split(' ').length
+    return this.syncCode.trim().split(/\s+/g).length
   },

   isCodeType: function(askingType) {

But... I don't know where syncCode is actually used to make sure that it's treated likewise is those places.

Sidenote: the code is inconsistently formatted - needs a .prettierrc.json