I am parsing a multiline value from a textarea encoded in the URL:
// URL Params:
?cn=asdf%20asdf&pn=asdf%20asdf&pe=asdf%40example.com&d=asdf%0A%0Aasdf&ye=test%40example.com&c=1234&tc=true
// JAVASCRIPT
var _url = window.location.href;
var _queryParams = decodeURIComponent( _url.split('?')[1] );
var _search = _queryParams;//location.search.substring(1);
var _data = JSON.parse('{"' + decodeURI(_search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}');
But I'm getting an Syntax Error: Unexpected token...
error from the JSON.parse()
function whenever I have a multiline text value in the d=
URL param above:
&d=asdf%0A%0Aasdf
What .replace()
regex pattern do I need to do to handle the line break encoding, %0A
?
EDIT:
I'm already successfully converting the URL params to a javascript object. The problem is that the replace([pattern match])
functions inside are choking on the mutliline text character: %0A
.