File tree Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -77,9 +77,11 @@ describe('handleTrailingSlash', () => {
7777 expect ( expectation ) . toBe ( 'https://example.com/' ) ;
7878 } ) ;
7979
80- it ( 'should never add trailing slashes to paths with file extensions ' , ( ) => {
81- const expectation = handleTrailingSlash ( '404.html' , 'always' ) ;
80+ it ( 'should never add trailing slashes to error pages ' , ( ) => {
81+ let expectation = handleTrailingSlash ( '404.html' , 'always' ) ;
8282 expect ( expectation ) . toBe ( '404.html' ) ;
83+ expectation = handleTrailingSlash ( 'https://example.com/403.html/403.html' , 'always' ) ;
84+ expect ( expectation ) . toBe ( 'https://example.com/403.html/403.html' ) ;
8385 } ) ;
8486} ) ;
8587
Original file line number Diff line number Diff line change 11import { posix as nodePath } from 'path' ;
22import { PluginOptions } from 'gatsby' ;
33
4+ const ERROR_PAGE_PATH_PATTERN = / [ 0 - 9 ] { 3 } \. ( [ 0 - 9 a - z ] + ) (?: [ ? # ] | $ ) / gim;
5+
46export const handleTrailingSlash = ( path : string , trailingSlashOption : PluginOptions [ 'trailingSlash' ] = 'always' ) => {
5- if ( path === '/' || path . length < 1 ) {
7+ if ( path === '/' || path . length < 1 || path . match ( ERROR_PAGE_PATH_PATTERN ) ) {
68 return path ;
79 }
810
You can’t perform that action at this time.
0 commit comments