inconsistencies in matchHeader for numbers
See original GitHub issuematchHeader
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:
- Restrict the second argument of
matchHeader
to be a string, regular expression or function and throw aTypeError
if anything else is passed in and modify the code inmatchStringOrRegexp
to use theString
constructor - 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 - Leave the matchHeader interface the same and modify
matchStringOrRegexp
to no longer do string coercion and usepattern.test(target)
instead oftarget.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:
- Created 6 years ago
- Reactions:1
- Comments:8 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
confirmed that the above tests pass now on master
Hey @gurpreetatwal, we’ll have a remote hackathon on Friday, wanna join us and work on this? You can comment here #1269