[ad_1]
I have a jquery html sanitizer function it removes (almost) all unwanted codes in content and in url, but spaces in url.
It doesn’t remove spaces and link tag with uncomleted url like this : <a href="//">Any text</a>
When I add replace(/\s+/gi, '');
to the function then it removes spaces in content is well and I get bunch of text without spaces.
What I want to do is, remove all spaces just in url, and tags like this <a href="//">Any text</a>
Here is my the code :
(function($) {
$.sanitize = function(input) {
var output = input.replace(/<script[^>]*?>.*?<\/script>/gi, '').
replace(/<[\/\!]*?[^<>]*?>/gi, '').
replace(/<style[^>]*?>.*?<\/style>/gi, '').
replace(/<![\s\S]*?--[ \t\n\r]*>/gi, '').
replace(/ /g, '');
return output;
};
})(jQuery);
$(function() {
$('#sanitize').click(function() {
var $input = $('#input').val();
$('#output').text($.sanitize($input));
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<textarea cols="30" rows="10" id="input"></textarea>
<p><button id="sanitize">Sanitize</button></p>
<p id="output"></p>
[ad_2]