0

I have a javascript array with special characters are getting populated from back-end database. I wanted to escape those characters on the front-end to form query string to get the results properly. my array shown below:

var a = new Array();
a[0] = "abc,def";
a[1] = "abc:def";
a[2] = "abc(def)";

my query string formation as shown below:

http://localhost:8080/search/?Ar=AND(OR(category1:abc,def),OR(category2:abc:def),OR(category3:abc(def)));

my query string parameter is getting separated by ':" character, but my data itself having ':' characters are failing my query to get the results. I triend encodeURIComponent() in-built functions, but it fails in linux box.Escape special characters should support both window and linux as well. Any help on this?

Ramkumar
  • 446
  • 1
  • 14
  • 30
  • What problem are you trying to solve? It's not like there're operating systems that can't read certain characters! – Álvaro González Aug 18 '14 at 07:13
  • 1
    What do you mean "fails in linux box"? What browser/Javascript engine/whatever are you using? How does it fail? – Karol S Aug 18 '14 at 07:14
  • 2
    Sounds like an XY problem to me... – Sinkingpoint Aug 18 '14 at 07:15
  • a[0] = escape("abc,def"); – john Aug 18 '14 at 07:19
  • `:` shouldn't have any side effects like that at that point in the URL. How are you trying to parse the URL on the server? What does "fails in the linux box mean"? Is Linux running on the client or the server? How does it fail? *Exactly* what URL does the browser's developer tools' net tab show is being requested? Is it really a Linux / Windows issue or do different browsers have different results? – Quentin Aug 18 '14 at 07:21
  • @KarolS: Fails on the java code to get the result properly, while doing an urlencode. – Ramkumar Aug 18 '14 at 07:23
  • I am trying to populate the query string through hidden input value and get the values in javascript and forming an above URL format and sent to back-end for results. – Ramkumar Aug 18 '14 at 07:25
  • @Maniram If it fails in the Java code, then we need to see the Java code too, and we need to know what exactly do you want to accomplish: sample inputs and outputs, or something like that. – Karol S Aug 18 '14 at 11:27

1 Answers1

1

i am not sure if i understood your problem. but if you want to escape some characters from an array, you can do soemthing like this.

var a = new Array();
a[0] = "abc,def";
a[1] = "abc:def";
a[2] = "abc(def)";

var excpList = [',',':','(', ')'];

var res = a.map(function(item,index,array){
           return item.split('').filter(function(item,index,array){
             if(excp.indexOf(item) < 0){
               return item;              
             }
           }).join('');
});

res --> ["abcdef", "abcdef", "abcdef"]

DEMO

Prabhu Murthy
  • 9,031
  • 5
  • 29
  • 36