Skip to content

Commit 96d74b1

Browse files
committed
Revert "Remove nette/neon patch for backward compatibility with old multi-line string encoding"
This reverts commit b1ea97a.
1 parent ce1f2bf commit 96d74b1

File tree

4 files changed

+363
-322
lines changed

4 files changed

+363
-322
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
"patches/DependencyChecker.patch"
120120
],
121121
"nette/neon": [
122+
"patches/NetteNeonStringNode.patch",
122123
"patches/NeonParser.patch"
123124
]
124125
}

composer.lock

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

patches/NetteNeonStringNode.patch

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--- src/Neon/Node/StringNode.php 2022-03-10 03:04:26
2+
+++ src/Neon/Node/StringNode.php 2024-08-26 14:53:45
3+
@@ -79,27 +79,18 @@
4+
5+
public function toString(): string
6+
{
7+
- if (strpos($this->value, "\n") === false) {
8+
- return "'" . str_replace("'", "''", $this->value) . "'";
9+
+ $res = json_encode($this->value, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
10+
+ if ($res === false) {
11+
+ throw new Nette\Neon\Exception('Invalid UTF-8 sequence: ' . $this->value);
12+
+ }
13+
14+
- } elseif (preg_match('~\n[\t ]+\'{3}~', $this->value)) {
15+
- $s = json_encode($this->value, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
16+
- $s = preg_replace_callback(
17+
- '#[^\\\\]|\\\\(.)#s',
18+
- function ($m) {
19+
- return ['n' => "\n", 't' => "\t", '"' => '"'][$m[1] ?? ''] ?? $m[0];
20+
- },
21+
- substr($s, 1, -1)
22+
- );
23+
- $s = str_replace('"""', '""\"', $s);
24+
- $delim = '"""';
25+
-
26+
- } else {
27+
- $s = $this->value;
28+
- $delim = "'''";
29+
+ if (strpos($this->value, "\n") !== false) {
30+
+ $res = preg_replace_callback('#[^\\\\]|\\\\(.)#s', function ($m) {
31+
+ return ['n' => "\n\t", 't' => "\t", '"' => '"'][$m[1] ?? ''] ?? $m[0];
32+
+ }, $res);
33+
+ $res = '"""' . "\n\t" . substr($res, 1, -1) . "\n" . '"""';
34+
}
35+
36+
- $s = preg_replace('#^(?=.)#m', "\t", $s);
37+
- return $delim . "\n" . $s . "\n" . $delim;
38+
+ return $res;
39+
}
40+
}

0 commit comments

Comments
 (0)