File tree Expand file tree Collapse file tree 3 files changed +23
-3
lines changed
Expand file tree Collapse file tree 3 files changed +23
-3
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 */
295296export 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 ) {
Original file line number Diff line number Diff 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
248264describe ( 'checkInternalLink' , ( ) => {
You can’t perform that action at this time.
0 commit comments