diff options
author | Jackson Tian <shyvo1987@gmail.com> | 2016-03-17 07:23:52 +0300 |
---|---|---|
committer | Benjamin Gruenbaum <inglor@gmail.com> | 2016-03-23 16:58:52 +0300 |
commit | 91466b855f0ced0df9a2d7444eea8ac7b89e278e (patch) | |
tree | 3b2db268ae1960f2343d414e527af8bdadbc6641 /lib/tls.js | |
parent | fb51c396ff823f8274bc4bea487da562ce57d75e (diff) |
lib: refactor code with startsWith/endsWith
reduce using RegExp for string test. This pull reuqest replaces
various usages of regular expressions in favor of the ES2015
startsWith and endsWith methods.
PR-URL: https://github.com/nodejs/node/pull/5753
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Diffstat (limited to 'lib/tls.js')
-rw-r--r-- | lib/tls.js | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/tls.js b/lib/tls.js index 1f7dcf39a15..808f8d417a9 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -75,7 +75,7 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) { // Create regexp to much hostnames function regexpify(host, wildcards) { // Add trailing dot (make hostnames uniform) - if (!/\.$/.test(host)) host += '.'; + if (!host || !host.endsWith('.')) host += '.'; // The same applies to hostname with more than one wildcard, // if hostname has wildcard when wildcards are not allowed, @@ -144,7 +144,7 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) { } } else if (cert.subject) { // Transform hostname to canonical form - if (!/\.$/.test(host)) host += '.'; + if (!host || !host.endsWith('.')) host += '.'; // Otherwise check all DNS/URI records from certificate // (with allowed wildcards) |