Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

encode parenthesis underscore tilt star with encodeURIComponent

encodeURIComponent escapes all characters except the following: - _ . ! ~ * ' ( )

But is it possible to extend the functionality encode the above special characters as well.

I know i can do something like this:

encodeURIComponent(str).replace(/\(/g, "%28").replace(/\)/g, "%29");

but I want functionality like this, without using additional functions on the encodeURIComponent

encodeURIComponent(str);
like image 666
STEEL Avatar asked Jul 30 '26 11:07

STEEL


1 Answers

  1. You should create your own function.
  2. You should create your own function, really.
  3. If you really know what you're doing, go to step 1.

Don't say I didn't warn you; there be dragons here:

(function() {
    var _fn = encodeURIComponent;

    window.encodeURIComponent = function(str) {
        return _fn(str).replace(/\(/g, "%28").replace(/\)/g, "%29");
    };
}());
like image 149
Ja͢ck Avatar answered Aug 01 '26 01:08

Ja͢ck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!