feat: escape filters from Jekyll, #443

This commit is contained in:
Yang Jun
2024-05-12 15:05:36 +08:00
committed by Jun Yang
parent 4955e75be7
commit b12eb8ab4b
13 changed files with 169 additions and 14 deletions
+4
View File
@@ -19,6 +19,10 @@ export function escape (str: string) {
return stringify(str).replace(/&|<|>|"|'/g, m => escapeMap[m])
}
export function xml_escape (str: string) {
return escape(str)
}
function unescape (str: string) {
return stringify(str).replace(/&(amp|lt|gt|#34|#39);/g, m => unescapeMap[m])
}
+8 -2
View File
@@ -1,4 +1,10 @@
import { stringify } from '../util/underscore'
export const url_decode = (x: string) => stringify(x).split('+').map(decodeURIComponent).join(' ')
export const url_encode = (x: string) => stringify(x).split(' ').map(encodeURIComponent).join('+')
export const url_decode = (x: string) => decodeURIComponent(stringify(x)).replace(/\+/g, ' ')
export const url_encode = (x: string) => encodeURIComponent(stringify(x)).replace(/%20/g, '+')
export const cgi_escape = (x: string) => encodeURIComponent(stringify(x))
.replace(/%20/g, '+')
.replace(/[!'()*]/g, c => '%' + c.charCodeAt(0).toString(16).toUpperCase())
export const uri_escape = (x: string) => encodeURI(stringify(x))
.replace(/%5B/g, '[')
.replace(/%5D/g, ']')