Skip to content

feat: support for relative URLs - #1552

Open
hazrid93 wants to merge 1 commit into
open-circle:mainfrom
hazrid93:hazrid93/25_1256
Open

feat: support for relative URLs#1552
hazrid93 wants to merge 1 commit into
open-circle:mainfrom
hazrid93:hazrid93/25_1256

Conversation

@hazrid93

@hazrid93 hazrid93 commented Jul 20, 2026

Copy link
Copy Markdown

Closes #1256.

Add a urlRelative(message?) action that accepts relative URLs (URL references without a scheme) by resolving them against a base; absolute URLs carrying a scheme (http:, mailto:, …) are rejected, the empty string is rejected, and values that throw under the URL constructor (e.g. // with an empty host) are rejected. The existing url action is unchanged.

Summary by CodeRabbit

  • New Features
    • Added a validation action for checking whether values are relative URLs.
    • Relative URL validation supports optional custom error messages.
    • Invalid, empty, or absolute URLs now produce a clear validation issue.

Closes open-circle#1256.

Add a `urlRelative(message?)` action that accepts relative URLs (URL references without a scheme) by resolving them against a base; absolute URLs carrying a scheme (http:, mailto:, …) are rejected, the empty string is rejected, and values that throw under the URL constructor (e.g. `//` with an empty host) are rejected. The existing `url` action is unchanged.
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request labels Jul 20, 2026
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds a urlRelative validation action that rejects empty strings and absolute URL schemes while validating other inputs with a base URL. Defines its issue and action types, overloads for optional messages, and runtime issue handling for typed invalid values. Re-exports the action through its directory entrypoint and the main actions barrel.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding support for relative URLs.
Linked Issues check ✅ Passed The PR adds a dedicated relative-URL validation action that fulfills the linked issue's request.
Out of Scope Changes check ✅ Passed The changes are limited to relative-URL support and the related exports.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@library/src/actions/urlRelative/urlRelative.ts`:
- Around line 39-42: Add a JSDoc comment immediately before the first exported
overload of urlRelative, describing the function’s purpose and documenting its
parameters, return behavior, and overload usage as appropriate. Keep the
existing overload signatures unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6ceb689c-0d3c-4f84-8113-aa7a87223178

📥 Commits

Reviewing files that changed from the base of the PR and between 90bc2c7 and c567552.

📒 Files selected for processing (3)
  • library/src/actions/index.ts
  • library/src/actions/urlRelative/index.ts
  • library/src/actions/urlRelative/urlRelative.ts

Comment on lines +39 to +42
export function urlRelative<TInput extends string>(): UrlRelativeAction<
TInput,
undefined
>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add JSDoc for the exported function.

As per coding guidelines, a JSDoc comment is required on the first overload of exported functions.

📝 Proposed JSDoc addition
+/**
+ * Creates a relative URL validation action.
+ *
+ * `@returns` A relative URL action.
+ */
 export function urlRelative<TInput extends string>(): UrlRelativeAction<
   TInput,
   undefined
 >;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export function urlRelative<TInput extends string>(): UrlRelativeAction<
TInput,
undefined
>;
/**
* Creates a relative URL validation action.
*
* `@returns` A relative URL action.
*/
export function urlRelative<TInput extends string>(): UrlRelativeAction<
TInput,
undefined
>;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@library/src/actions/urlRelative/urlRelative.ts` around lines 39 - 42, Add a
JSDoc comment immediately before the first exported overload of urlRelative,
describing the function’s purpose and documenting its parameters, return
behavior, and overload usage as appropriate. Keep the existing overload
signatures unchanged.

Source: Coding guidelines

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

2 issues found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="library/src/actions/urlRelative/urlRelative.ts">

<violation number="1" location="library/src/actions/urlRelative/urlRelative.ts:10">
P1: Absolute URLs preceded by URL-parser-trimmed whitespace are accepted, violating the scheme rejection guarantee. Check for a scheme after leading parser-trimmed whitespace before resolving the reference.</violation>

<violation number="2" location="library/src/actions/urlRelative/urlRelative.ts:39">
P3: This new public validation action has no tests, so acceptance/rejection behavior—including empty strings, scheme-relative references, and absolute schemes—can regress without detection. Add runtime and declaration tests following `actions/url` conventions.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic


function isRelativeUrl(value: string): boolean {
if (value === '') return false;
if (/^[a-z][a-z0-9+.-]*:/i.test(value)) return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1: Absolute URLs preceded by URL-parser-trimmed whitespace are accepted, violating the scheme rejection guarantee. Check for a scheme after leading parser-trimmed whitespace before resolving the reference.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At library/src/actions/urlRelative/urlRelative.ts, line 10:

<comment>Absolute URLs preceded by URL-parser-trimmed whitespace are accepted, violating the scheme rejection guarantee. Check for a scheme after leading parser-trimmed whitespace before resolving the reference.</comment>

<file context>
@@ -0,0 +1,68 @@
+
+function isRelativeUrl(value: string): boolean {
+  if (value === '') return false;
+  if (/^[a-z][a-z0-9+.-]*:/i.test(value)) return false;
+  try {
+    new URL(value, 'http://example.com');
</file context>

readonly message: TMessage;
}

export function urlRelative<TInput extends string>(): UrlRelativeAction<

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: This new public validation action has no tests, so acceptance/rejection behavior—including empty strings, scheme-relative references, and absolute schemes—can regress without detection. Add runtime and declaration tests following actions/url conventions.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At library/src/actions/urlRelative/urlRelative.ts, line 39:

<comment>This new public validation action has no tests, so acceptance/rejection behavior—including empty strings, scheme-relative references, and absolute schemes—can regress without detection. Add runtime and declaration tests following `actions/url` conventions.</comment>

<file context>
@@ -0,0 +1,68 @@
+  readonly message: TMessage;
+}
+
+export function urlRelative<TInput extends string>(): UrlRelativeAction<
+  TInput,
+  undefined
</file context>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for relative URLs

1 participant