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

Fixing getting local files (file://) failed #2470

Merged
merged 7 commits into from Mar 23, 2020
Merged

Conversation

Alanscut
Copy link
Collaborator

fixing issue #2416 and #2396

@@ -11,7 +11,8 @@ var createError = require('./createError');
*/
module.exports = function settle(resolve, reject, response) {
var validateStatus = response.config.validateStatus;
if (!validateStatus || validateStatus(response.status)) {
var responseUrl = response.config.url;
if (!validateStatus || validateStatus(response.status) || (!response.status && ~responseUrl.indexOf('file:'))) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

the tilde bitwise logic returns -1 when the string doesn't match and 0 when it matches, I believe it will always be false? unless I'm missing something

> myString = "test123"
"test123"
> ~myString.indexOf("test");
-1
> ~myString.indexOf("notpresent");
0

You can just do the normal .indexOf('file:') >= 0 or something similar

Copy link
Collaborator Author

@Alanscut Alanscut Oct 25, 2019

Choose a reason for hiding this comment

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

hi, -1 is true rather than false...

var i = -1;
if (i) {
    console.log(i, " is true");
} else {
    console.log(i, " is false");
}

it will ouput: -1 ' is true'

Copy link
Collaborator

Choose a reason for hiding this comment

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

🤦‍♂️ right

@yasuf
Copy link
Collaborator

yasuf commented Oct 25, 2019

and about the build, we're working on it, hopefully we have it passing soon

@Alanscut
Copy link
Collaborator Author

Thanks @yasuf !

@Alanscut
Copy link
Collaborator Author

Alanscut commented Nov 8, 2019

Hi @yasuf , since you have approved this PR, will you merge it?

lib/core/settle.js Outdated Show resolved Hide resolved
test/specs/requests.spec.js Outdated Show resolved Hide resolved
test/specs/requests.spec.js Outdated Show resolved Hide resolved
@chinesedfan chinesedfan changed the title fix issue #2416, #2396--Getting local files (file://) fail Fixing getting local files (file://) failed Mar 12, 2020
@chinesedfan chinesedfan merged commit 885ada6 into axios:master Mar 23, 2020
@Alanscut Alanscut deleted the issue-1 branch March 24, 2020 03:21
@axios axios locked and limited conversation to collaborators May 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants