Commit 44a978c
authored
Fix the handling of escaping in table cells (#391)
Using `str_replace` to perform the un-escaping is flawed because it
performs each of its search in order, which was not handling properly
the case of escaped backslashes.
Replacing escape sequences requires handling each backslash a single
time, to avoid considering the output of an escaped backslash as belong
to another escape sequence (or considering a backslash as being the
start of an escape sequence instead of being escape, depending on the
order). The solution for that is to use `preg_replace` matching a
backslash and its following character, thanks to the fact that this
function guarantees that it does not have overlapping matches for the
regex.
I extracted that parsing to a private method for 2 reasons:
1. we need an assertion to assume that the returned value is not `null`
(here, I'm assuming that the regex does not fail. I could turn that in
an exception if you prefer, but we already do the same assumption for
the splitting of cells)
2. a oneliner (which would use `??` to handle the null values) would
make that line quite hard to read1 parent 85febc9 commit 44a978c
2 files changed
+17
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
753 | 753 | | |
754 | 754 | | |
755 | 755 | | |
756 | | - | |
| 756 | + | |
757 | 757 | | |
758 | 758 | | |
759 | 759 | | |
| |||
764 | 764 | | |
765 | 765 | | |
766 | 766 | | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
767 | 783 | | |
768 | 784 | | |
769 | 785 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
63 | 62 | | |
64 | 63 | | |
65 | 64 | | |
| |||
0 commit comments