Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ext/node): use primordials in ext/node/polyfills/_http_common.ts #24281

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions ext/node/polyfills/_http_common.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// Copyright Joyent and Node contributors. All rights reserved. MIT license.

// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials

const tokenRegExp = /^[\^_`a-zA-Z\-0-9!#$%&'*+.|~]+$/;
import { primordials } from "ext:core/mod.js";
const { RegExpPrototypeTest, SafeRegExp } = primordials;
const tokenRegExp = new SafeRegExp(/^[\^_`a-zA-Z\-0-9!#$%&'*+.|~]+$/);
/**
* Verifies that the given val is a valid HTTP token
* per the rules defined in RFC 7230
* See https://tools.ietf.org/html/rfc7230#section-3.2.6
*/
function checkIsHttpToken(val: string) {
return tokenRegExp.test(val);
return RegExpPrototypeTest(tokenRegExp, val);
}

const headerCharRegex = /[^\t\x20-\x7e\x80-\xff]/;
const headerCharRegex = new SafeRegExp(/[^\t\x20-\x7e\x80-\xff]/);
/**
* True if val contains an invalid field-vchar
* field-value = *( field-content / obs-fold )
* field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
* field-vchar = VCHAR / obs-text
*/
function checkInvalidHeaderChar(val: string) {
return headerCharRegex.test(val);
return RegExpPrototypeTest(headerCharRegex, val);
}

export const chunkExpression = /(?:^|\W)chunked(?:$|\W)/i;
export const chunkExpression = new SafeRegExp(/(?:^|\W)chunked(?:$|\W)/i);
export {
checkInvalidHeaderChar as _checkInvalidHeaderChar,
checkIsHttpToken as _checkIsHttpToken,
Expand Down