Skip to content

Commit 1092590

Browse files
committed
Remove unused rejectPreEncoded function
The rejectPreEncoded function is exported but never used in production code. validateResourceId already rejects any % character via RESOURCE_ID_FORBIDDEN, making the more specific %XX hex pattern check redundant.
1 parent 7ff8323 commit 1092590

File tree

2 files changed

+0
-70
lines changed

2 files changed

+0
-70
lines changed

src/lib/input-validation.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ import { ValidationError } from "./errors.js";
2828
*/
2929
const RESOURCE_ID_FORBIDDEN = /[?#%\s]/;
3030

31-
/**
32-
* Matches `%XX` hex-encoded sequences (e.g., `%2F`, `%20`, `%3A`).
33-
* Used to detect pre-encoded strings that would get double-encoded.
34-
*/
35-
const PRE_ENCODED_PATTERN = /%[0-9a-fA-F]{2}/;
36-
3731
/**
3832
* Matches ASCII control characters (code points 0x00–0x1F).
3933
* These are invisible and have no valid use in CLI string inputs.
@@ -110,27 +104,6 @@ export function rejectControlChars(input: string, label: string): void {
110104
}
111105
}
112106

113-
/**
114-
* Reject pre-URL-encoded sequences (`%XX`) in resource identifiers.
115-
*
116-
* Resource IDs (slugs, issue IDs) should always be plain strings. If they
117-
* contain `%XX` patterns, they were likely pre-encoded by an agent and
118-
* would get double-encoded when interpolated into API URLs.
119-
*
120-
* @param input - String to validate
121-
* @param label - Human-readable name for error messages (e.g., "project slug")
122-
* @throws {ValidationError} When input contains percent-encoded sequences
123-
*/
124-
export function rejectPreEncoded(input: string, label: string): void {
125-
const match = PRE_ENCODED_PATTERN.exec(input);
126-
if (match) {
127-
throw new ValidationError(
128-
`Invalid ${label}: contains URL-encoded sequence "${match[0]}".\n` +
129-
` Use plain text instead of percent-encoding (e.g., "my project" not "my%20project").`
130-
);
131-
}
132-
}
133-
134107
/**
135108
* Validate a resource identifier (org slug, project slug, or issue ID component).
136109
*

test/lib/input-validation.property.test.ts

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
} from "fast-check";
2121
import {
2222
rejectControlChars,
23-
rejectPreEncoded,
2423
validateEndpoint,
2524
validateResourceId,
2625
} from "../../src/lib/input-validation.js";
@@ -42,19 +41,6 @@ const validEndpointArb = stringMatching(
4241
/** Characters that should be rejected in resource IDs */
4342
const injectionCharArb = constantFrom("?", "#", "%20", " ", "\t", "\n");
4443

45-
/** Pre-encoded sequences that should be rejected */
46-
const preEncodedArb = constantFrom(
47-
"%2F",
48-
"%20",
49-
"%3A",
50-
"%3F",
51-
"%23",
52-
"%00",
53-
"%0A",
54-
"%7E",
55-
"%41"
56-
);
57-
5844
/** Control characters (ASCII 0x00-0x1F) as strings */
5945
const controlCharArb = constantFrom(
6046
"\x00",
@@ -122,35 +108,6 @@ describe("rejectControlChars properties", () => {
122108
});
123109
});
124110

125-
describe("rejectPreEncoded properties", () => {
126-
test("valid slugs without percent signs always pass", async () => {
127-
await fcAssert(
128-
property(validSlugArb, (input) => {
129-
rejectPreEncoded(input, "test");
130-
}),
131-
{ numRuns: DEFAULT_NUM_RUNS }
132-
);
133-
});
134-
135-
test("any string with %XX hex pattern always throws", async () => {
136-
await fcAssert(
137-
property(tuple(validSlugArb, preEncodedArb), ([prefix, encoded]) => {
138-
const input = `${prefix}${encoded}`;
139-
expect(() => rejectPreEncoded(input, "test")).toThrow(
140-
/URL-encoded sequence/
141-
);
142-
}),
143-
{ numRuns: DEFAULT_NUM_RUNS }
144-
);
145-
});
146-
147-
test("percent sign followed by non-hex does not throw", () => {
148-
// "%ZZ" is not a valid encoding — we only reject real %XX patterns
149-
rejectPreEncoded("my-org%ZZstuff", "test");
150-
rejectPreEncoded("my-org%Gxstuff", "test");
151-
});
152-
});
153-
154111
describe("validateResourceId properties", () => {
155112
test("valid slugs always pass", async () => {
156113
await fcAssert(

0 commit comments

Comments
 (0)