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

lib: refactor code with startsWith/endsWith #5753

Closed
wants to merge 1 commit into from

Conversation

JacksonTian
Copy link
Contributor

Pull Request check-list

Please make sure to review and check all of these items:

  • Does make -j8 test (UNIX) or vcbuild test nosign (Windows) pass with
    this change (including linting)?
  • Is the commit message formatted according to CONTRIBUTING.md?
  • If this change fixes a bug (or a performance problem), is a regression
    test (or a benchmark) included?
  • Is a documentation update included (if this change modifies
    existing APIs, or introduces new ones)?

NOTE: these things are not required to open a PR and can be done
afterwards / while the PR is open.

Affected core subsystem(s)

lib

Description of change

reduce using REGExp for string test.

@mscdex
Copy link
Contributor

mscdex commented Mar 17, 2016

Did you run the relevant benchmarks before and after these changes?

@JacksonTian
Copy link
Contributor Author

I run the os.tmpdir after change, the benchmarks have no effect.

Should I do a benchmark for RegExp vs startsWith/endsWith?

@mscdex mscdex added the lib / src Issues and PRs related to general changes in the lib or src directory. label Mar 17, 2016
if (settings.execArgv.some(function(s) { return /^--prof/.test(s); }) &&
!settings.execArgv.some(function(s) { return /^--logfile=/.test(s); }))
{
if (settings.execArgv.some(function(s) {
Copy link
Member

Choose a reason for hiding this comment

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

These can probably be arrow functions.

@JacksonTian
Copy link
Contributor Author

Hi @ronkorving @benjamingr , I updated the PR with your suggestions. Thanks.

@@ -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 += '.';
Copy link
Contributor

Choose a reason for hiding this comment

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

What does the !host check add?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the host maybe undefined.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can it really? In that case, the old code would have produced "undefined.". Does that code path really exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes. If no !host path, make test will fails.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, it wouldn't have blown up, but would've turned undefined into "undefined", before appending a period to it. My point is, this was never a bug, so do we need that !host check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need it here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, my bad. I get it now.

@benjamingr
Copy link
Member

@JacksonTian
Copy link
Contributor Author

The windows is unhappy, I forget to check the length of string.

Updated it. Would you please run CI again.

@benjamingr
Copy link
Member

@jasnell
Copy link
Member

jasnell commented Mar 22, 2016

There were multiple CI failures that appear unrelated but should be investigated before this lands.

@benjamingr
Copy link
Member

They say insanity is doing the same thing twice and expecting different results but I've had a long day so I'll give it another shot before investigating the CI results further: https://ci.nodejs.org/job/node-test-pull-request/2029/console

@benjamingr
Copy link
Member

The CI failure seems unrelated to this. Going to land.

@benjamingr
Copy link
Member

Wait, I just realized no one has given this a LGTM yet and I'm not completely sure about all the code involved myself - so I'd rather wait for another collaborator to LGTM it before landing.

@benjamingr
Copy link
Member

Ok, reviewed now and LGTM. Ping @nodejs/collaborators I'd love this to get a second review.

!settings.execArgv.some(function(s) { return /^--logfile=/.test(s); }))
{
if (settings.execArgv.some((s) => s.startsWith('--prof')) &&
!settings.execArgv.some((s) => s.startsWith('--logfile='))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The indentation here is slightly off by two spaces.

reduce using RegExp for string test.
@JacksonTian
Copy link
Contributor Author

Thanks @benjamingr , fixed it.

@benjamingr
Copy link
Member

Thanks! Landed in 91466b8

@benjamingr benjamingr closed this Mar 23, 2016
benjamingr pushed a commit that referenced this pull request Mar 23, 2016
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: #5753
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
@JacksonTian JacksonTian deleted the starts/ends branch March 23, 2016 14:38
evanlucas pushed a commit that referenced this pull request Mar 30, 2016
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: #5753
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
evanlucas pushed a commit that referenced this pull request Mar 31, 2016
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: #5753
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
evanlucas pushed a commit that referenced this pull request Mar 31, 2016
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: #5753
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
MylesBorins pushed a commit that referenced this pull request Apr 8, 2016
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: #5753
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
@MylesBorins MylesBorins mentioned this pull request Apr 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lib / src Issues and PRs related to general changes in the lib or src directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants