8000 Merge in master to get ReST escaping... · pyodide/sphinx-js@0600fa7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0600fa7

Browse files
committed
Merge in master to get ReST escaping...
...which I suspect I need to make the `\"` in my new tests come out right.
2 parents c3c70db + 5899410 commit 0600fa7

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

sphinx_js/renderers.py

Lines changed: 8 additions & 3 deletions
< 8000 td data-grid-cell-id="diff-30b3c4e3c348699c98d042be505f0f514d7e4645611d6932c97f41f851c9d163-295-300-1" data-selected="false" role="gridcell" style="background-color:var(--bgColor-default);text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative diff-line-number-neutral left-side">300
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from jinja2 import Environment, PackageLoader
99
from six import iteritems
1010
from sphinx.errors import SphinxError
11+
from sphinx.util import rst
1112

1213
from .parsers import PathVisitor
1314
from .suffix_tree import SuffixAmbiguous, SuffixNotFound
@@ -273,7 +274,7 @@ def _params_formatter(field, description):
273274
types = _or_types(field)
274275
if types:
275276
heads.append(types)
276-
heads.append(field['name'])
277+
heads.append(rst.escape(field['name']))
277278
tail = description
278279
return heads, tail
279280

@@ -290,8 +291,12 @@ def _exceptions_formatter(field, description):
290291

291292
def _or_types(field):
292293
"""Return all the types in a doclet subfield like "params" or "returns"
293-
with vertical bars between them, like "number|string"."""
294-
return '|'.join(field.get('type', {}).get('names', []))
294+
with vertical bars between them, like "number|string".
295+
296+
ReST-escape the types.
297+
298+
"""
299+
return rst.escape('|'.join(field.get('type', {}).get('names', [])))
295

296301

297302
def _dotted_path(segments):

tests/test_build/source/code.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,10 @@ function destructuredParams(p1, {foo, bar}) {}
158158
* @param [e]
159159
*/
160160
function defaultValues(a, b, c="true", d=true, e=null) {}
161+
162+
/**
163+
* @param a_
164+
* @param {type_} b
165+
* @returns {rtype_}
166+
*/
167+
function injection() {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.. js:autofunction:: injection

tests/test_build/test_build.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,18 @@ def test_no_shadowing(self):
177177
'avoid_shadowing',
178178
'more_code.shadow()\n\n Another thing named shadow, to threaten to shadow the one in\n code.js\n')
179179

180+
def test_restructuredtext_injection(self):
181+
"""Make sure param names and types are escaped and cannot be
182+
interpreted as RestructuredText."""
183+
self._file_contents_eq(
184+
'injection',
185+
u'injection(a_, b)\n\n'
186+
' Arguments:\n'
187+
' * **a_** --\n\n'
188+
' * **b** (*type_*) --\n\n'
189+
' Returns:\n'
190+
' **rtype_** --\n')
191+
180192

181193
DESCRIPTION = """
182194

0 commit comments

Comments
 (0)
0