File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
Expand file tree Collapse file tree 2 files changed +21
-1
lines changed 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