Files
react-native-devtools-frontend/node_modules/micromark/lib/util/normalize-uri.js
T
Tim van der Lippe efb716af67 Update linter packages
- Updates stylelint to 13.8.0
- Updates ESLint to 7.14.0
- Updates @typescript-eslint to 4.9.0

DISABLE_THIRD_PARTY_CHECK=NPM update
R=jacktfranklin@chromium.org

Change-Id: I207e204607ede782710e042c17d6510c7f696905
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2566806
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
2020-12-01 16:04:40 +00:00

69 lines
1.6 KiB
JavaScript

module.exports = normalizeUri
var codes = require('../character/codes')
var values = require('../character/values')
var asciiAlphanumeric = require('../character/ascii-alphanumeric')
var fromCharCode = require('../constant/from-char-code')
// Encode unsafe characters with percent-encoding, skipping already
// encoded sequences.
function normalizeUri(value) {
var index = -1
var result = []
var start = 0
var skip = 0
var code
var next
var replace
while (++index < value.length) {
code = value.charCodeAt(index)
// A correct percent encoded value.
if (
code === codes.percentSign &&
asciiAlphanumeric(value.charCodeAt(index + 1)) &&
asciiAlphanumeric(value.charCodeAt(index + 2))
) {
skip = 2
}
// ASCII.
else if (code < 128) {
if (!/[!#$&-;=?-Z_a-z~]/.test(fromCharCode(code))) {
replace = fromCharCode(code)
}
}
// Astral.
else if (code > 55295 && code < 57344) {
next = value.charCodeAt(index + 1)
// A correct surrogate pair.
if (code > 55295 && code < 56320 && next > 56319 && next < 57344) {
replace = fromCharCode(code, next)
skip = 1
}
// Lone surrogate.
else {
replace = values.replacementCharacter
}
}
// Unicode.
else {
replace = fromCharCode(code)
}
if (replace) {
result.push(value.slice(start, index), encodeURIComponent(replace))
start = index + skip + 1
replace = undefined
}
if (skip) {
index += skip
skip = 0
}
}
return result.join('') + value.slice(start)
}