更新时间:2023-02-14 11:27:44
只有一个简短的字符列表,可以安全地在URL的路径组件。
There is only a short list of characters that can be safely carried through in a path component of a URL.
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
所有其他字符都必须删除(如果你'创造一个slu)或逃脱。
All the other characters will have to be either removed (if you're creating a "slug") or escaped.
可以使用正则表达式 / [^ a-zA-Z0-9 -._〜] /
进行删除>。
Removal can be done with the regex /[^a-zA-Z0-9-._~]/
.
可以使用 encodeURIComponent()
完成转义。
如果您希望获得相当于ICONV的音译(即将é
转换为 e
和€
进入 EUR
),你必须自己动手,尽管你可以利用现有解决方案并可能转换音译表为JS格式。
If you wish to achieve an equivalent of ICONV transliteration (that is, turning é
into e
and €
into EUR
), you'll have to do your own, although you can leverage existing solutions and perhaps transform a transliteration table to JS format.