Skip to content

Fix: fix url component parsing bug#9747

Open
lslvxy wants to merge 7 commits intoKong:developfrom
lslvxy:fix/fix-url-component-parsing-bug
Open

Fix: fix url component parsing bug#9747
lslvxy wants to merge 7 commits intoKong:developfrom
lslvxy:fix/fix-url-component-parsing-bug

Conversation

@lslvxy
Copy link
Copy Markdown

@lslvxy lslvxy commented Mar 25, 2026

When a Url is constructed from a string containing Nunjucks template tags ({{ }} / {% %}), urlObject is intentionally left undefined to avoid the native URL parser percent-encoding the tags. This caused getHost(), getPath(), and getRemote() to always return '' for any templated URL.

Changes

  • urls.ts — Added regex fallbacks in getHost(), getPath(), and getRemote() that extract the relevant segment directly from this.origin when this.urlObject is undefined. Patterns extracted into three named module-level constants for clarity:
const URL_HOST_PATTERN  = /^(?:https?:\/\/)?([^\/:]+)/i;        // hostname, no port
const URL_PATH_PATTERN  = /^(?:https?:\/\/[^\/]+)(\/[^?#]*)/i;  // path, no query/hash
const URL_REMOTE_PATTERN = /^(?:https?:\/\/)?([^\/]+)/i;        // host + port

Example — previously all three returned '':

const url = new Url('http://{{ host }}:8080/api/v1');
url.getHost();   // '{{ host }}'
url.getPath();   // '/api/v1'
url.getRemote(); // '{{ host }}:8080'
  • urls.test.ts — New test covering host-only tags, path tags, host+port tags, Nunjucks block tags ({% %}), and no-path URLs.

Link Issue #9746

Copilot AI review requested due to automatic review settings March 25, 2026 06:52
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 25, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ lslvxy
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes Url.getHost(), getPath(), and getRemote() returning empty strings when Url parsing is intentionally skipped for templated URLs (e.g. Nunjucks {{ }} / {% %}), by adding regex-based fallbacks that extract host/path/remote from this.origin.

Changes:

  • Add module-level regex constants and fallback parsing in getHost(), getPath(), and getRemote() when urlObject is undefined.
  • Add tests covering templated host, templated path, host+port, block tags, and no-path URLs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/insomnia-scripting-environment/src/objects/urls.ts Adds regex fallbacks to extract host/path/remote directly from the original string when native URL parsing is skipped.
packages/insomnia-scripting-environment/src/objects/tests/urls.test.ts Adds unit tests validating fallback behavior for common templated URL shapes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@lslvxy
Copy link
Copy Markdown
Author

lslvxy commented Mar 25, 2026

@copilot open a new pull request to apply changes based on the comments in this thread

lslvxy and others added 2 commits March 25, 2026 15:32
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…urls.test.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@lslvxy
Copy link
Copy Markdown
Author

lslvxy commented Mar 25, 2026

@copilot open a new pull request to apply changes based on the comments in this thread

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.

4 participants