Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/utils/repo-path.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const MAX_REPO_PATH_LENGTH = 512

const REPO_PATH_SEGMENT_PATTERN = /^[a-zA-Z0-9._$+\[\]()-]+$/
const REPO_PATH_SEGMENT_PATTERN = /^[a-zA-Z0-9@._$+\[\]()-]+$/

export function isValidRepoPath(path: string) {
if (path === '') {
Expand Down
34 changes: 34 additions & 0 deletions tests/scoped-docs-paths.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import { isValidRepoPath } from '../src/utils/repo-path'
import { resolveDocsPathRedirect } from '../src/utils/docs-redirects'

const docsPath =
'reference/@tanstack/namespaces/IR/variables/INCLUDES_SCALAR_FIELD'
test('scoped generated reference paths pass both content and route validation', () => {
assert.equal(isValidRepoPath(`docs/${docsPath}.md`), true)
assert.deepEqual(
resolveDocsPathRedirect({
defaultDocs: 'overview',
docsPath,
frameworks: [],
manifest: { paths: [docsPath], redirects: {} },
}),
{ type: 'render', docsPath },
)
})
test('scoped path support preserves traversal and URL delimiter rejection', () => {
for (const path of [
'@scope/../secret',
'@scope/./secret',
'@scope//secret',
'@scope/%2e%2e/secret',
'@scope/file?raw=1',
'@scope/file#fragment',
'@scope\\secret',
'//user@host/file',
'https://user@host/file',
]) {
assert.equal(isValidRepoPath(path), false, path)
}
})
Loading