JavaScript: What characters are not encoded by encodeURIComponent?

I am writing my own function in another language, and I want it to provide identical results, if possible.

+5
source share
2 answers

You can find the information in the MDC documentation :

encodeURIComponentdeletes all characters except the following:
alphabetic, decimal digits,- _ . ! ~ * ' ( )

+7
source

The short answer is, you can combine all code units UTF-16 encodeURIComponentwill encode using the following:

/[^a-zA-Z0-9\-_.!~*'()]/g

however, the spec says it handles additional code points with 4-byte UTF-8 encodings.

, ES 262

15.1.3.4 encodeURIComponent (uriComponent)

encodeURIComponent URI, , , , UTF-8 . encodeURIComponent uriComponent, :

  • componentString - ToString (uriComponent).

  • unescapedURIComponentSet , , uriUnescaped.

  • Encode (componentString, unescapedURIComponentSet)

uriUnescaped

uriUnescaped: uriAlpha | DecimalDigit | uriMark

uriAlpha: a b c d e f g h j k l m n o p q r s t u v w x y z A B C D E F G H J K L M N O P Q R S T U V W X Y Z

uriMark: - _.! ~ * '()

DecimalDigit: 0 1 2 3 4 5 6 7 8 9

+3

All Articles