Skip to content

Commit 979e992

Browse files
committed
Only allow alphanumeric/underscore characters through StringHelper::toHandle()
Resolves #15772
1 parent cbccf95 commit 979e992

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Auto-generated handles, slugs, etc. now update immediately when the source input is changed. ([#15754](https://github.com/craftcms/cms/issues/15754))
66
- Fixed a bug where Table fields’ Default Values table could lose existing rows if they only consisted of Dropdown columns without configured options.
77
- Fixed a bug where custom fields’ `required` properties were always `false`. ([#15752](https://github.com/craftcms/cms/issues/15752))
8+
- Fixed a bug where `craft\helpers\StringHelper::toHandle()` was allowing non-alphanumeric/underscore characters through. ([#15772](https://github.com/craftcms/cms/pull/15772))
89

910
## 4.12.3 - 2024-09-14
1011

src/helpers/StringHelper.php

+3
Original file line numberDiff line numberDiff line change
@@ -1811,6 +1811,9 @@ public static function toHandle(string $str): string
18111811
// Handle must start with a letter
18121812
$handle = preg_replace('/^[^a-z]+/', '', $handle);
18131813

1814+
// Replace any remaining non-alphanumeric or underscore characters with spaces
1815+
$handle = preg_replace('/[^a-z0-9_]/', ' ', $handle);
1816+
18141817
return static::toCamelCase($handle);
18151818
}
18161819

tests/unit/helpers/StringHelperTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -2206,6 +2206,10 @@ public function toHandleDataProvider(): array
22062206
['fooBar', 'Fo’o Bar'],
22072207
['fooBarBaz', 'Foo Ba’r Baz'],
22082208
['fooBar', '0 Foo Bar'],
2209+
['fooBar', 'Foo!Bar'],
2210+
['fooBar', 'Foo,Bar'],
2211+
['fooBar', 'Foo/Bar'],
2212+
['fooBar', 'Foo\\Bar'],
22092213
];
22102214
}
22112215

0 commit comments

Comments
 (0)