Skip to content

Commit c6766c3

Browse files
authored
Merge pull request #9 from LibreSign/fix/always-return-bar
chore: always return bar
2 parents 30a8894 + 04a8b61 commit c6766c3

3 files changed

Lines changed: 13 additions & 9 deletions

File tree

src/helpers.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ function translate_path($page, ?string $target_locale = null): string
5959
$partial_path = '';
6060
}
6161

62-
return match (true) {
62+
$match = match (true) {
6363
$target_locale === packageDefaultLocale($page) => $partial_path,
6464
default => "/{$target_locale}".($partial_path === '/' ? '' : $partial_path),
6565
};
66+
67+
return ! empty($match) ? $match : '/';
6668
}
6769

6870
/**
@@ -91,10 +93,12 @@ function locale_path($page, string $partial_path, ?string $target_locale = null)
9193
$partial_path = '';
9294
}
9395

94-
return match (true) {
96+
$match = match (true) {
9597
$target_locale === packageDefaultLocale($page) => $partial_path,
9698
default => "/{$target_locale}".($partial_path === '/' ? '' : $partial_path),
9799
};
100+
101+
return ! empty($match) ? $match : '/';
98102
}
99103

100104
/**

tests/unit/LocalePathTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ public static function providerLocalePath(): array
1616
{
1717
return [
1818
// Handling empty paths
19-
['', null, ''],
19+
['', null, '/'],
2020
['', 'ar', '/ar'],
2121

2222
// Root path handling
23-
['/', null, ''],
23+
['/', null, '/'],
2424
['/', 'ar', '/ar'],
25-
['/', packageDefaultLocale(), ''],
25+
['/', packageDefaultLocale(), '/'],
2626

2727
// Basic path translation
2828
['blog', null, '/blog'],

tests/unit/TranslatePathTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ public static function providerTranslatePath(): array
6161

6262
// Testing `/` as a root path (edge case)
6363
['/', 'ar', '/ar'],
64-
['/', null, ''],
65-
['/', packageDefaultLocale(), ''],
64+
['/', null, '/'],
65+
['/', packageDefaultLocale(), '/'],
6666

6767
// Testing paths with unrecognized prefixes (should keep them)
6868
['/custom-path/blog', 'fr-CA', '/fr-CA/custom-path/blog'],
@@ -74,7 +74,7 @@ public static function providerTranslatePath(): array
7474

7575
// Handling an empty path (should default to `/`)
7676
['', 'ar', '/ar'],
77-
['', null, ''],
77+
['', null, '/'],
7878

7979
// Deeply nested paths
8080
['/es/a/b/c/d/e', 'ar', '/ar/a/b/c/d/e'],
@@ -91,7 +91,7 @@ public static function providerTranslatePath(): array
9191

9292
// Handling trailing slashes
9393
['/es/', 'ar', '/ar'],
94-
['/fr-CA/', null, ''],
94+
['/fr-CA/', null, '/'],
9595
['/blog/', 'ar', '/ar/blog'],
9696

9797
/**

0 commit comments

Comments
 (0)