fix: use regex to avoid falsely replacing ports starting with 80 #124
+1
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes #120.
Problem Statement
Following what the issue addresses, the following logic is currently used to remove
:80
when the baseURL starts withhttp://
.http/lib/module.js
Lines 117 to 120 in c002aaa
However, this logic will also be true for ANY ports that starts with
:80
, such as:8081
,:8000
and so on since they do technically contain:80
in them.PR Fix
We can use the regex
/^http:\/\/.*:80$/
to make the check stricter, which requires the baseURL to fulfill all the following conditions:http://
(^http:\/\/
:^
means "start of line" and we need to escape/
into\/
).*
:.
means any character and*
means appearing zero or more times):80
only (:80$
:$
means "end of line")Test Results
Test Case 1 - baseURL ends with :80
Both logic works as intended.
Test Case 2 - baseURL ends with :8081
Here we can see the original logic falsely turns
http://localhost:8081
tohttp://localhost81
(as reported by the issue) whereas the regex logic will not trigger as intended.