Open
Description
Package containing the bug
next-drupal (NPM package)
Describe the bug
In next-drupal
version 2.0.0, the NextDrupalBase.addLocalePrefix()
fails to add a proper locale prefix if the given path starts with the same letters as the locale. This affects the results from NextDrupalPages.translatePathFromContext()
among others.
Expected behavior and steps to reproduce:
Expected value for test
would be /en/enable/testing
, but /enable/testing
is returned instead:
import { NextDrupal } from "next-drupal"
const drupal = new NextDrupal("https://example.com")
const test = drupal.addLocalePrefix('/enable/testing/', {
locale: 'en',
default_locale: 'fi'
})
Additional context
I believe the issue comes from this condition:
if (locale && !path.startsWith(`/${locale}`) && locale !== defaultLocale) {
localePrefix = `/${locale}`
}
Maybe replacing startsWith(`/${locale}`)
with startsWith(`/${locale}/`)
would do the trick?