Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions library/src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export * from './trimStart/index.ts';
export * from './types.ts';
export * from './ulid/index.ts';
export * from './url/index.ts';
export * from './urlRelative/index.ts';
export * from './uuid/index.ts';
export * from './value/index.ts';
export * from './values/index.ts';
Expand Down
1 change: 1 addition & 0 deletions library/src/actions/urlRelative/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './urlRelative.ts';
68 changes: 68 additions & 0 deletions library/src/actions/urlRelative/urlRelative.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import type {
BaseIssue,
BaseValidation,
ErrorMessage,
} from '../../types/index.ts';
import { _addIssue } from '../../utils/index.ts';

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>

try {
new URL(value, 'http://example.com');
return true;
} catch {
return false;
}
}

export interface UrlRelativeIssue<TInput extends string>
extends BaseIssue<TInput> {
readonly kind: 'validation';
readonly type: 'url_relative';
readonly expected: null;
readonly received: `"${string}"`;
readonly requirement: (input: string) => boolean;
}

export interface UrlRelativeAction<
TInput extends string,
TMessage extends ErrorMessage<UrlRelativeIssue<TInput>> | undefined,
> extends BaseValidation<TInput, TInput, UrlRelativeIssue<TInput>> {
readonly type: 'url_relative';
readonly reference: typeof urlRelative;
readonly expects: null;
readonly requirement: (input: string) => boolean;
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>

TInput,
undefined
>;
Comment on lines +39 to +42

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


export function urlRelative<
TInput extends string,
const TMessage extends ErrorMessage<UrlRelativeIssue<TInput>> | undefined,
>(message: TMessage): UrlRelativeAction<TInput, TMessage>;

// @__NO_SIDE_EFFECTS__
export function urlRelative(
message?: ErrorMessage<UrlRelativeIssue<string>>,
): UrlRelativeAction<string, ErrorMessage<UrlRelativeIssue<string>> | undefined> {
return {
kind: 'validation',
type: 'url_relative',
reference: urlRelative,
async: false,
expects: null,
requirement: isRelativeUrl,
message,
'~run'(dataset, config) {
if (dataset.typed && !this.requirement(dataset.value)) {
_addIssue(this, 'URL', dataset, config);
}
return dataset;
},
};
}