Fix MCP occurrence apostrophe escaping
This commit is contained in:
1 parent
85834a0498
commit
8733ce6148
2 files changed
+31
-4
No files matched your search
@@ -66,7 +66,7 @@ function market_management_sanitize_multiline_html(?string $value): ?string
|
|||||||
|
|
||||||
$tokens = preg_split('/(<\/?a\b[^>]*>|<br\s*\/?>|<\/?strong\s*>)/iu', $value, -1, PREG_SPLIT_DELIM_CAPTURE);
|
$tokens = preg_split('/(<\/?a\b[^>]*>|<br\s*\/?>|<\/?strong\s*>)/iu', $value, -1, PREG_SPLIT_DELIM_CAPTURE);
|
||||||
if ($tokens === false) {
|
if ($tokens === false) {
|
||||||
return htmlspecialchars($value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
return htmlspecialchars($value, ENT_NOQUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = '';
|
$result = '';
|
||||||
@@ -89,7 +89,7 @@ function market_management_sanitize_multiline_html(?string $value): ?string
|
|||||||
$result .= '</a>';
|
$result .= '</a>';
|
||||||
$anchorOpen = false;
|
$anchorOpen = false;
|
||||||
} else {
|
} else {
|
||||||
$result .= htmlspecialchars($token, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
$result .= htmlspecialchars($token, ENT_NOQUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -103,7 +103,7 @@ function market_management_sanitize_multiline_html(?string $value): ?string
|
|||||||
$anchorOpen = true;
|
$anchorOpen = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$result .= htmlspecialchars($token, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
$result .= htmlspecialchars($token, ENT_NOQUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
||||||
}
|
}
|
||||||
if ($anchorOpen) {
|
if ($anchorOpen) {
|
||||||
$result .= '</a>';
|
$result .= '</a>';
|
||||||
@@ -1106,7 +1106,6 @@ function market_management_get_occurrence(PDO $pdo, int $occurrenceId, bool $inc
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
market_management_sanitize_occurrence_payload($occurrence);
|
|
||||||
$costSummary = $pdo->prepare(
|
$costSummary = $pdo->prepare(
|
||||||
'SELECT COALESCE(SUM(gross_amount), 0) AS gross_amount,
|
'SELECT COALESCE(SUM(gross_amount), 0) AS gross_amount,
|
||||||
COALESCE(SUM(net_amount), 0) AS net_amount,
|
COALESCE(SUM(net_amount), 0) AS net_amount,
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../../modules/market_management/service.php';
|
||||||
|
|
||||||
|
function fail_test(string $message): void
|
||||||
|
{
|
||||||
|
fwrite(STDERR, $message . PHP_EOL);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function assert_test(bool $condition, string $message): void
|
||||||
|
{
|
||||||
|
if (!$condition) {
|
||||||
|
fail_test($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$plainText = "Test 'A' & <B> \"C\"";
|
||||||
|
$sanitized = market_management_sanitize_multiline_html($plainText);
|
||||||
|
assert_test($sanitized === "Test 'A' & <B> \"C\"", 'Plain text must preserve quotes and escape markup characters once');
|
||||||
|
|
||||||
|
$link = '<a href="https://erpnaurua.imhochrain.ch/files.php?path=Marktmanagement%2Fvertrag.pdf">Vertrag</a>';
|
||||||
|
$sanitizedLink = market_management_sanitize_multiline_html($link);
|
||||||
|
assert_test(str_contains($sanitizedLink, 'class="sg-hyperlink"'), 'Allowed links must remain links');
|
||||||
|
assert_test(str_contains($sanitizedLink, 'href="https://erpnaurua.imhochrain.ch/files.php?path=Marktmanagement%2Fvertrag.pdf"'), 'Link href must remain valid');
|
||||||
|
|
||||||
|
fwrite(STDOUT, "market_management_sanitizer_test: OK\n");
|
||||||
Reference in new issue
Block a user