Skip to content

Commit 3e88122

Browse files
merge branch v2 (release 2.0.0-beta.50)
2 parents c1c0bbe + 5378793 commit 3e88122

8 files changed

Lines changed: 46 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
# Changelog
22

3-
## [v2.0.0-beta.49](https://github.com/marcantondahmen/automad/commit/ef38ad1d6590d0a9208812981bb907f9074f1257)
3+
## [v2.0.0-beta.50](https://github.com/marcantondahmen/automad/commit/395d62584987b5fb149a9b322b8206b708f57818)
44

5-
Sat, 18 Jul 2026 17:42:18 +0200
5+
Sun, 19 Jul 2026 12:24:34 +0200
6+
7+
### Bugfixes
8+
9+
- fix search and replace with html special characters ([395d62584](https://github.com/marcantondahmen/automad/commit/395d62584987b5fb149a9b322b8206b708f57818))
10+
11+
## [v2.0.0-beta.49](https://github.com/marcantondahmen/automad/commit/c1c0bbe84dbca1ee70db59d5b89967d0193da1b1)
12+
13+
Sat, 18 Jul 2026 17:45:06 +0200
614

715
### New Features
816

automad/src/server/App.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
* @license See LICENSE.md for license information
5757
*/
5858
class App {
59-
const VERSION = '2.0.0-beta.49';
59+
const VERSION = '2.0.0-beta.50';
6060

6161
/**
6262
* Required PHP version.

automad/src/server/Models/Search/Search.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ class Search {
6969
*/
7070
private string $searchValue;
7171

72+
/**
73+
* The search value with encoded HTML special characters.
74+
*/
75+
private string $searchValueSafeHtml;
76+
7277
/**
7378
* Strip tags before performing search.
7479
*/
@@ -93,13 +98,15 @@ public function __construct(
9398
?bool $stripTags = false
9499
) {
95100
$this->searchValue = preg_quote($searchValue, '/');
101+
$this->searchValueSafeHtml = preg_quote(htmlspecialchars($searchValue), '/');
96102
$this->regexFlags = 'ims';
97103
$this->pagesToSearch = $pagesToSearch;
98104
$this->stripTags = $stripTags;
99105
$this->SearchIndex = $SearchIndexCache->getIndex();
100106

101107
if ($isRegex) {
102108
$this->searchValue = str_replace('/', '\/', $searchValue);
109+
$this->searchValueSafeHtml = str_replace('/', '\/', htmlspecialchars($searchValue));
103110
}
104111

105112
if ($isCaseSensitive) {
@@ -150,6 +157,7 @@ public function searchTextField(string $field, string $content): ?FieldResults {
150157

151158
$contextRegex = '/(?:^|\s).{0,50}' . $this->searchValue . '.{0,50}(?:\s|$)/' . $this->regexFlags;
152159
$searchRegex = '/' . $this->searchValue . '/' . $this->regexFlags;
160+
$searchRegexSafeHtml = '/' . $this->searchValueSafeHtml . '/' . $this->regexFlags;
153161

154162
preg_match_all(
155163
$contextRegex,
@@ -171,7 +179,7 @@ public function searchTextField(string $field, string $content): ?FieldResults {
171179
$parts[] = preg_replace(
172180
'/\s+/',
173181
' ',
174-
trim(preg_replace($searchRegex, '<mark>$0</mark>', htmlspecialchars($ctx[0])) ?? '')
182+
trim(preg_replace($searchRegexSafeHtml, '<mark>$0</mark>', htmlspecialchars($ctx[0])) ?? '')
175183
);
176184
}
177185
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"draft": {
3+
"title": "HTML",
4+
"html": "Text with HTML <span>entities</span>."
5+
}
6+
}
7+

automad/tests/main/data/html/data

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"draft": {
3+
"title": "HTML",
4+
"html": "Text&nbsp;with HTML <span>entities</span>."
5+
}
6+
}
7+

automad/tests/main/src/Models/Search/ReplacementTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ public static function dataForTestReplaceInDataIsSame() {
5050
Data::load('/text'),
5151
Data::load('/text-replaced')
5252
),
53+
// HTML, no regex, not case sensitive.
54+
array(
55+
'&nbsp;',
56+
' ',
57+
false,
58+
false,
59+
array('html'),
60+
Data::load('/html'),
61+
Data::load('/html-replaced')
62+
),
5363
// Text, no regex, case sensitive.
5464
array(
5565
'/url/To/page',

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "automad",
3-
"version": "2.0.0-beta.49",
3+
"version": "2.0.0-beta.50",
44
"description": "Automad",
55
"author": "Marc Anton Dahmen",
66
"private": true,

0 commit comments

Comments
 (0)