글 작성자: 써니루루

쿼리 스트링(Query string)을 자바스크립트로 받아서 클라이언트 상에서 처리를 해야하는 경우가 많이 있게된다.

이런 때에 주소에 공백이 들어가거나 하는 경우에 문제가 생기는데 이를 제대로 처리하기 위해 공백을 2번 변환하는 과정이 필요하게 된다.

다음 아래 소스를 확인해서 차후에 작업에 문제가 생기지 않도록 하자.



// URI의 공백 처리 / 특수문자 제거


strInput=window.location.search.substring(1,window.location.search.length);

strInput = String(strInput.replace(/%2520/g,"%20"));



//공백 제거

spaces = new RegExp("\%20", "g");

strPath = strPath.replace(spaces , " ");


//특수문자 제거

forbiddenChars = new RegExp("[<>\'\"]", "g"); // Global search/replace

strPath = strPath.replace(forbiddenChars, "");