From 46673eed42a8496118fec95a100c9d621eff7c7c Mon Sep 17 00:00:00 2001 From: Richard Pospesel Date: Wed, 16 Oct 2019 14:37:27 -0700 Subject: [PATCH] Bug 32111: Fixed issue parsing user-provided brige strings Fixed parseBridgeStrings function in parseFunctions.jsm to now discard 'bridge' string prefix in user-provided bridge strings. Also now properly handling carriage returns ('\r') in bridge strings. --- .../torpreferences/content/parseFunctions.jsm | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/browser/components/torpreferences/content/parseFunctions.jsm b/browser/components/torpreferences/content/parseFunctions.jsm index a6e6c554ca634..954759de63a5e 100644 --- a/browser/components/torpreferences/content/parseFunctions.jsm +++ b/browser/components/torpreferences/content/parseFunctions.jsm @@ -53,7 +53,7 @@ let parseUsernamePassword = function(aUsernameColonPassword) { return [username, password]; }; -// expects tring in the format: ADDRESS:PORT,ADDRESS:PORT,... +// expects a string in the format: ADDRESS:PORT,ADDRESS:PORT,... // returns array of ports (as ints) let parseAddrPortList = function(aAddrPortList) { let addrPorts = aAddrPortList.split(","); @@ -62,10 +62,23 @@ let parseAddrPortList = function(aAddrPortList) { return retval; }; -// expects a '/n' delimited string of bridge string, which we split and trim +// expects a '/n' or '/r/n' delimited bridge string, which we split and trim +// each bridge string can also optionally have 'bridge' at the beginning ie: +// bridge $(type) $(address):$(port) $(certificate) +// we strip out the 'bridge' prefix here let parseBridgeStrings = function(aBridgeStrings) { + + // replace carriage returns ('\r') with new lines ('\n') + aBridgeStrings = aBridgeStrings.replace(/\r/g, "\n"); + // then replace contiguous new lines ('\n') with a single one + aBridgeStrings = aBridgeStrings.replace(/[\n]+/g, "\n"); + + // split on the newline and for each bridge string: trim, remove starting 'bridge' string + // finally discard entries that are empty strings; empty strings could occur if we receive + // a new line containing only whitespace let splitStrings = aBridgeStrings.split("\n"); - return splitStrings.map(val => val.trim()); + return splitStrings.map(val => val.trim().replace(/^bridge\s+/i, "")) + .filter(bridgeString => bridgeString != ""); }; // expecting a ',' delimited list of ints with possible white space between -- GitLab