1
0
Fork 0

`command.ts` generalize substitutions

Looks better than repeating the same thing over and over...
pull/1472/head
Eli Barzilay 2023-07-20 06:46:12 -04:00 committed by GitHub
parent 91d3933eb5
commit bfd23b02d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 10 deletions

View File

@ -77,18 +77,15 @@ class Command {
}
}
function escapeChar(ch: string): string {
return ch.replace(/[%\r\n:,]/g, c =>
'%' + c.charCodeAt(0).toString(16).toUpperCase().padStart(2, '0'))
}
function escapeData(s: any): string {
return toCommandValue(s)
.replace(/%/g, '%25')
.replace(/\r/g, '%0D')
.replace(/\n/g, '%0A')
return toCommandValue(s).replace(/%\r\n/g, escapeChar)
}
function escapeProperty(s: any): string {
return toCommandValue(s)
.replace(/%/g, '%25')
.replace(/\r/g, '%0D')
.replace(/\n/g, '%0A')
.replace(/:/g, '%3A')
.replace(/,/g, '%2C')
return toCommandValue(s).replace(/[%\r\n:,]/g, escapeChar)
}