11import { describe , it , expect } from 'bun:test' ;
22
3- import { getURLLookupAlternatives } from './middleware' ;
3+ import { getURLLookupAlternatives , normalizeURL } from './middleware' ;
44
55describe ( 'getURLLookupAlternatives' , ( ) => {
66 it ( 'should return all URLs up to the root' , ( ) => {
@@ -104,3 +104,29 @@ describe('getURLLookupAlternatives', () => {
104104 ] ) ;
105105 } ) ;
106106} ) ;
107+
108+ describe ( 'normalizeURL' , ( ) => {
109+ it ( 'should remove trailing slashes' , ( ) => {
110+ expect ( normalizeURL ( new URL ( 'https://docs.mycompany.com/hello/' ) ) ) . toEqual (
111+ new URL ( 'https://docs.mycompany.com/hello' ) ,
112+ ) ;
113+ } ) ;
114+
115+ it ( 'should remove duplicate slashes' , ( ) => {
116+ expect ( normalizeURL ( new URL ( 'https://docs.mycompany.com//hello//there' ) ) ) . toEqual (
117+ new URL ( 'https://docs.mycompany.com/hello/there' ) ,
118+ ) ;
119+ } ) ;
120+
121+ it ( 'should convert uppercase characters in the path to lowercase' , ( ) => {
122+ expect ( normalizeURL ( new URL ( 'https://docs.mycompany.com/Hello/My/pAge' ) ) ) . toEqual (
123+ new URL ( 'https://docs.mycompany.com/hello/my/page' ) ,
124+ ) ;
125+ } ) ;
126+
127+ it ( 'should not affect uppercase characters in querystring parameters' , ( ) => {
128+ expect ( normalizeURL ( new URL ( 'https://docs.mycompany.com/Hello/My/pAge?Q=MySearch' ) ) ) . toEqual (
129+ new URL ( 'https://docs.mycompany.com/hello/my/page?Q=MySearch' ) ,
130+ ) ;
131+ } ) ;
132+ } )
0 commit comments