Skip to content

Commit c9cc0ba

Browse files
authored
Merge pull request #43853 from github/repo-sync
Repo sync
2 parents d8588ba + 948e815 commit c9cc0ba

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

src/frame/components/context/MainContext.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export type MainContextT = {
125125
hidden: boolean
126126
noEarlyAccessBanner: boolean
127127
applicableVersions: string[]
128-
docsTeamMetrics?: string[]
128+
docsTeamMetrics: string[] | null
129129
} | null
130130
relativePath?: string
131131
sidebarTree?: ProductTreeNode | null
@@ -228,7 +228,7 @@ export const getMainContext = async (req: any, res: any): Promise<MainContextT>
228228
applicableVersions: req.context.page?.permalinks.map((obj: any) => obj.pageVersion) || [],
229229
hidden: req.context.page.hidden || false,
230230
noEarlyAccessBanner: req.context.page.noEarlyAccessBanner || false,
231-
docsTeamMetrics: req.context.page.docsTeamMetrics || undefined,
231+
docsTeamMetrics: req.context.page.docsTeamMetrics || null,
232232
}) ||
233233
null
234234

src/links/lib/extract-links.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,17 @@ export function getRelativePath(filePath: string): string {
288288
/**
289289
* Normalize a link path for comparison with pageMap
290290
*
291+
* - Removes query strings
291292
* - Removes trailing slashes
292293
* - Removes anchor fragments
293294
* - Ensures leading slash
294295
*/
295296
export function normalizeLinkPath(href: string): string {
297+
// Remove query string
298+
let normalized = href.split('?')[0]
299+
296300
// Remove anchor
297-
let normalized = href.split('#')[0]
301+
normalized = normalized.split('#')[0]
298302

299303
// Remove trailing slash
300304
if (normalized.endsWith('/') && normalized.length > 1) {

src/links/tests/extract-links.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,22 @@ describe('normalizeLinkPath', () => {
243243
'/en/enterprise-server@3.10/admin/overview',
244244
)
245245
})
246+
247+
test('removes query string', () => {
248+
expect(normalizeLinkPath('/actions/guides?tab=cli')).toBe('/actions/guides')
249+
})
250+
251+
test('removes query string before anchor fragment', () => {
252+
expect(normalizeLinkPath('/actions/guides?tab=cli#section')).toBe('/actions/guides')
253+
})
254+
255+
test('removes query string with trailing slash', () => {
256+
expect(normalizeLinkPath('/actions/guides/?tab=cli')).toBe('/actions/guides')
257+
})
258+
259+
test('handles path with only a query string (no anchor)', () => {
260+
expect(normalizeLinkPath('/repositories/overview?version=3')).toBe('/repositories/overview')
261+
})
246262
})
247263

248264
describe('checkInternalLink', () => {

0 commit comments

Comments
 (0)