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

Fix issue with empty headers #37

Merged
merged 2 commits into from
Dec 26, 2021
Merged

Fix issue with empty headers #37

merged 2 commits into from
Dec 26, 2021

Conversation

bkniffler
Copy link
Contributor

If for some reason a header value is undefined/null, we get an error (can't call function replace of undefined). We could filter out empty headers also, but if the header is there and empty, maybe we'd still want it output?

@codecov
Copy link

codecov bot commented Dec 22, 2021

Codecov Report

Merging #37 (94fb2ef) into master (3af4e6d) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master       #37   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines           43        43           
  Branches        18        18           
=========================================
  Hits            43        43           
Impacted Files Coverage Δ
src/main.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3af4e6d...94fb2ef. Read the comment docs.

Copy link
Owner

@leoek leoek left a comment

Choose a reason for hiding this comment

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

Hi @bkniffler thanks for the contribution! Can you check my review comment? This would fix #35 if it is consitent with the browsers fetch api and node-fetch.

src/main.js Outdated
@@ -42,7 +42,7 @@ export const isInstanceOfHeaders = (val) => {
* @property {String} params - The header params as string
*/

const getHeaderString = (name, val) => ` -H "${name}: ${val.replace(/(\\|")/g, '\\$1')}"`;
const getHeaderString = (name, val) => ` -H "${name}: ${(val || '').replace(/(\\|")/g, '\\$1')}"`;
Copy link
Owner

Choose a reason for hiding this comment

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

I'd probably use `${val}`.replace instead of (val || '').replace to be consistent with the implementation of node-fetch and the browsers fetch api.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting, thanks for linking the issue, wasn't aware of browser implementation. I'll change it right away!

Copy link
Owner

Choose a reason for hiding this comment

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

Thanks, this fixes #35 now :) I'll keep #35 open until we have some regression tests.

Be more consistent with browser fetch when handling undefined/null headers
@leoek leoek self-requested a review December 26, 2021 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants