Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
fixup! lib: replace String global with primordials
  • Loading branch information
targos committed Oct 2, 2020
commit 04bc26cd40a68d5951c6df4aff46c88b84399cd1
17 changes: 13 additions & 4 deletions lib/tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const {
ObjectDefineProperty,
ObjectFreeze,
StringFromCharCode,
StringPrototypeCharCodeAt,
StringPrototypeReplace,
StringPrototypeSplit,
} = primordials;

const {
Expand Down Expand Up @@ -138,11 +141,17 @@ function unfqdn(host) {
return host.replace(/[.]$/, '');
}

// String#toLowerCase() is locale-sensitive so we use
// a conservative version that only lowercases A-Z.
function toLowerCase(c) {
return StringFromCharCode(32 + StringPrototypeCharCodeAt(c, 0));
}

function splitHost(host) {
// String#toLowerCase() is locale-sensitive so we use
// a conservative version that only lowercases A-Z.
const replacer = (c) => StringFromCharCode(32 + c.charCodeAt(0));
return unfqdn(host).replace(/[A-Z]/g, replacer).split('.');
return StringPrototypeSplit(
StringPrototypeReplace(unfqdn(host), /[A-Z]/g, toLowerCase),
'.'
);
Comment on lines +151 to +154
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ljharb @Trott I made the change, but I don't really like how the code looks like (that's why I'm currently only pushing for use of static primordials)...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instance method primordials are used often in the node codebase; imo "how it looks" is only relevant once robustness against user code is assured.

}

function check(hostParts, pattern, wildcards) {
Expand Down