提交 8ee536df 编写于 作者: S Slobodan Mišković 提交者: Joe Haddad

Fix canonical rel link generation (#9357)

上级 b6af38d2
......@@ -18,10 +18,10 @@ export function isBlockedPage(pathname: string): boolean {
export function cleanAmpPath(pathname: string): string {
if (pathname.match(/\?amp=(y|yes|true|1)/)) {
pathname = pathname.replace(/\?amp=(y|yes|true|1)/, '?')
pathname = pathname.replace(/\?amp=(y|yes|true|1)&?/, '?')
}
if (pathname.match(/&amp=(y|yes|true|1)/)) {
pathname = pathname.replace(/\?amp=(y|yes|true|1)/, '')
pathname = pathname.replace(/&amp=(y|yes|true|1)/, '')
}
pathname = pathname.replace(/\?$/, '')
return pathname
......
/* eslint-env jest */
import { cleanAmpPath } from 'next/dist/next-server/server/utils'
// convenince function so tests can be alligned neatly
// and easy to eyeball
const check = (input, expected) =>
expect(cleanAmpPath(input)).toBe(expected)
describe('cleanAmpPath', () => {
it('should leave url unchanged when no apm parameter is present', () =>
check(
'/some/path?param=blah',
'/some/path?param=blah'
)
)
it('should handle amp as the only parameter', () =>
check(
'/some/path?amp=1',
'/some/path'
)
)
it('should handle amp as the first parameter', () =>
check(
'/some/path?amp=1&page=10',
'/some/path?page=10'
)
)
it('should handle amp as the middle parameter', () =>
check(
'/some/path?page=10&amp=1&last=here',
'/some/path?page=10&last=here'
)
)
it('should handle amp as the last parameter', () =>
check(
'/some/path?page=10&amp=1',
'/some/path?page=10'
)
)
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册