-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix(scripts): keep {{variables}} intact in req.getHost() #9240
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
Open
dhananjaypesu
wants to merge
1
commit into
usebruno:main
Choose a base branch
from
dhananjaypesu:fix/9233-9234-get-host-variables
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+72
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| const { describe, it, expect } = require('@jest/globals'); | ||
| const BrunoRequest = require('../src/bruno-request'); | ||
|
|
||
| const getHost = (url) => new BrunoRequest({ url, method: 'GET', headers: {} }).getHost(); | ||
|
|
||
| describe('BrunoRequest - getHost()', () => { | ||
| describe('interpolated urls', () => { | ||
| it('returns the host and port', () => { | ||
| expect(getHost('http://localhost:5000/api')).toBe('localhost:5000'); | ||
| }); | ||
|
|
||
| it('lowercases a literal hostname, as URL does', () => { | ||
| expect(getHost('https://API.Example.com/users')).toBe('api.example.com'); | ||
| }); | ||
|
|
||
| it('returns an empty string for a url it cannot parse', () => { | ||
| expect(getHost('not a url')).toBe(''); | ||
| }); | ||
| }); | ||
|
|
||
| describe('urls still holding {{variables}}', () => { | ||
| it('keeps the case of a variable in the hostname', () => { | ||
| // #9234: `new URL()` lowercased this to `{{host}}`, which no longer interpolates | ||
| expect(getHost('https://{{HOST}}/test')).toBe('{{HOST}}'); | ||
| }); | ||
|
|
||
| it('returns the variable when it carries the scheme as well', () => { | ||
| // #9233: `{{HOST}}/test` has no scheme, so `new URL()` threw and this was '' | ||
| expect(getHost('{{HOST}}/test')).toBe('{{HOST}}'); | ||
| }); | ||
|
|
||
| it('keeps a port, literal or variable', () => { | ||
| expect(getHost('http://{{host}}:{{port}}/x')).toBe('{{host}}:{{port}}'); | ||
| expect(getHost('http://{{Host}}:8080/x')).toBe('{{Host}}:8080'); | ||
| }); | ||
|
|
||
| it('stops at a query string or fragment', () => { | ||
| expect(getHost('{{baseUrl}}?page=1')).toBe('{{baseUrl}}'); | ||
| expect(getHost('https://{{HOST}}#section')).toBe('{{HOST}}'); | ||
| }); | ||
|
|
||
| it('drops userinfo', () => { | ||
| expect(getHost('https://{{user}}:{{pass}}@{{HOST}}/x')).toBe('{{HOST}}'); | ||
| }); | ||
|
|
||
| it('leaves a literal host alone when only the path has variables', () => { | ||
| expect(getHost('https://API.Example.com/users/{{id}}')).toBe('api.example.com'); | ||
| }); | ||
| }); | ||
| }); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Handle unresolved schemes in
getRawHostWhen
this.req.urlis{{protocol}}://{{HOST}}/path, the scheme pattern does not match.getRawHost()returns{{protocol}}:, soBrunoRequest.getHost()exposes the wrong value to pre-request scripts. For example,bru.interpolate(req.getHost())produceshttps:instead of the host. Strip unresolved{{...}}://prefixes before extracting the authority, and add this case tobruno-request-get-host.spec.js.🤖 Prompt for AI Agents