0
I가이 정규식/자바 스크립트 코드 :
toReturn = toReturn.replace(/(\[url=)(.+)(\])(.+)(\[\/url\])/g, '<a target=\"_blank\" href="\$2">\$4</a>');
그러나 문제이며, 사용자가 입력하는 경우 :
[url=example]example[/url]
some_other_text
[url=example2]example2[/url]
그것은 것 첫 번째 [url =]을 마지막 [/ url]과 연결하십시오. 하나의 잘못된 URL 만들기 !!!!!
어떻게 해결할 수 있습니까?
사용자가'[url = javascript : location = http : //evil.org] [/ url]'또는'[url = ">
And how would I stop that Mike Samuel? –
by white-listing URLs by protocol, and properly encoding both the HTML attribute value and the HTML text node using entity escapes. –