Skip to content

Commit 407e8d1

Browse files
committed
DOP-2638: Handle escaped double-quotes
1 parent 3ca1f90 commit 407e8d1

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

snooty/rstparser.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ def unescape_backslashes(text: str) -> str:
9292
"""docutils replaces backslashes with null characters. Deal with this in
9393
a fairly inane way that matches how backslashes seem to be used in our
9494
corpus."""
95-
return text.replace("\x00<", "<").replace("\x00>", ">").replace("\x00", "\\")
95+
return (
96+
text.replace("\x00<", "<")
97+
.replace("\x00>", ">")
98+
.replace('\x00"', '"')
99+
.replace("\x00", "\\")
100+
)
96101

97102

98103
def parse_explicit_title(text: str) -> Tuple[str, Optional[str]]:

snooty/test_postprocess.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2245,3 +2245,42 @@ def test_targets_with_backslashes() -> None:
22452245
</root>
22462246
""",
22472247
)
2248+
2249+
2250+
def test_target_quotes() -> None:
2251+
with make_test(
2252+
{
2253+
Path(
2254+
"source/index.txt"
2255+
): r"""
2256+
:writeconcern:`majority <\"majority\">`
2257+
:writeconcern:`majority <"majority">`
2258+
2259+
.. writeconcern:: "majority"
2260+
"""
2261+
}
2262+
) as result:
2263+
assert not result.diagnostics[FileId("index.txt")]
2264+
print(ast_to_testing_string(result.pages[FileId("index.txt")].ast))
2265+
2266+
check_ast_testing_string(
2267+
result.pages[FileId("index.txt")].ast,
2268+
"""
2269+
<root fileid="index.txt">
2270+
<paragraph>
2271+
<ref_role domain="mongodb" name="writeconcern" target="writeconcern.&quot;majority&quot;" fileid="['index', 'mongodb-writeconcern-writeconcern.-majority-']">
2272+
<literal><text>majority</text></literal>
2273+
</ref_role><text></text>
2274+
<ref_role domain="mongodb" name="writeconcern" target="writeconcern.&quot;majority&quot;" fileid="['index', 'mongodb-writeconcern-writeconcern.-majority-']">
2275+
<literal><text>majority</text></literal>
2276+
</ref_role>
2277+
</paragraph>
2278+
2279+
<target domain="mongodb" name="writeconcern" html_id="mongodb-writeconcern-writeconcern.-majority-">
2280+
<directive_argument><literal><text>"majority"</text></literal></directive_argument>
2281+
<target_identifier ids="['writeconcern.&quot;majority&quot;']">
2282+
<text>"majority"</text>
2283+
</target_identifier>
2284+
</target>
2285+
</root>""",
2286+
)

0 commit comments

Comments
 (0)