feat: support for relative URLs - #1552
Conversation
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.
WalkthroughAdds a 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
library/src/actions/index.tslibrary/src/actions/urlRelative/index.tslibrary/src/actions/urlRelative/urlRelative.ts
| export function urlRelative<TInput extends string>(): UrlRelativeAction< | ||
| TInput, | ||
| undefined | ||
| >; |
There was a problem hiding this comment.
📐 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.
| 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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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< |
There was a problem hiding this comment.
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>
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 existingurlaction is unchanged.Summary by CodeRabbit