Skip to content

Commit 527cfb3

Browse files
committed
fix(core): avoid regex in host normalization
1 parent 507fb22 commit 527cfb3

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

packages/core/src/validators/externalRefResolver.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,17 @@ function ipv6LiteralFromHost(host: string): string | undefined {
115115
return host.startsWith('[') && host.endsWith(']') ? host.slice(1, -1) : undefined;
116116
}
117117

118+
function stripTrailingDnsRootDots(host: string): string {
119+
let end = host.length;
120+
while (end > 0 && host.codePointAt(end - 1) === 46) {
121+
end--;
122+
}
123+
124+
return end === host.length ? host : host.slice(0, end);
125+
}
126+
118127
function normalizeHostForPolicy(host: string): string {
119-
return ipv6LiteralFromHost(host) === undefined ? host.replace(/\.+$/, '') : host;
128+
return ipv6LiteralFromHost(host) === undefined ? stripTrailingDnsRootDots(host) : host;
120129
}
121130

122131
function isBlockedIPv6Literal(host: string): boolean {

0 commit comments

Comments
 (0)