question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

inconsistencies in matchHeader for numbers

See original GitHub issue

matchHeader has inconsistent behavior when trying to match headers that contain numbers. Due to a truthy check that was introduced to the matchStringOrRegexp method in lib/common.js in #827, numbers other than 0 get converted to string before matching but 0 does not.

Given the headers

zero: 0
one: 1

The following would happen

.matchHeader('zero', 0) -> true
.matchHeader('one', 1) -> false
.matchHeader('zero', '0') -> false
.matchHeader('one', '1') -> true

The interface could be cleaned up in one of three ways:

  1. Restrict the second argument of matchHeader to be a string, regular expression or function and throw a TypeError if anything else is passed in and modify the code in matchStringOrRegexp to use the String constructor
  2. If the second argument is not a regular expression or a function, coerce into a string before comparison and perform the same modification to matchStringOrRegexp as above
  3. Leave the matchHeader interface the same and modify matchStringOrRegexp to no longer do string coercion and use pattern.test(target) instead of target.match(pattern)

I personally like doing the second option as well as changing matchStringOrRegexp to dopattern.test(target) instead of target.match(pattern)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
gr2mcommented, Jun 9, 2019

confirmed that the above tests pass now on master

1reaction
gr2mcommented, Dec 13, 2018

Hey @gurpreetatwal, we’ll have a remote hackathon on Friday, wanna join us and work on this? You can comment here #1269

Read more comments on GitHub >

github_iconTop Results From Across the Web

matchHeader w/ regex fails on numbers · Issue #197 · nock/nock
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue...
Read more >
K-1 Number Sense Trajectory | Questioning My Metacognition
As part of the workshop, teachers were asked to engage in a Number Sense Trajectory Cut-N-Sort. match header and descriptor ...
Read more >
ORA-01163: SIZE clause indicates 32768 (blocks), but should ...
ORA-01163: SIZE clause indicates 32768 (blocks), but should match header. ... statement does not equate to the number of blocks recorded in the...
Read more >
csv-parse error handling in pipe - Stack Overflow
I have the process running relatively smoothly, but am stuck on one item - catching the errors throw by an inconsistent number of...
Read more >
HTTP/1.1: Caching in HTTP
The goal of caching in HTTP/1.1 is to eliminate the need to send requests in many cases, and to eliminate the need to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found