commit 7aca86c1666873378ab6b9845acdee93b16468a9 Author: Richard Pospesel richard@torproject.org Date: Wed Oct 16 14:37:27 2019 -0700
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 a6e6c554ca63..5873c6339983 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,... +// expect 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 string of 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 foreach bridge string: trim, remove starting 'bridge' string + // finally discard entries that are empty string; empty string 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
tbb-commits@lists.torproject.org