mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
latex: Raise error if invalid dimension value
This commit is contained in:
parent
4bc5a242ce
commit
cb00f51328
@ -277,11 +277,12 @@ def escape_abbr(text):
|
||||
|
||||
def rstdim_to_latexdim(width_str):
|
||||
"""Convert `width_str` with rst length to LaTeX length."""
|
||||
match = re.match('(\d*\.?\d*)\s*(\S*)', width_str)
|
||||
match = re.match('^(\d*\.?\d*)\s*(\S*)$', width_str)
|
||||
if not match:
|
||||
raise ValueError
|
||||
res = width_str
|
||||
amount, unit = match.groups()[:2]
|
||||
float(amount) # validate amount is float
|
||||
if not unit:
|
||||
return None
|
||||
elif unit == 'pt':
|
||||
|
@ -11,6 +11,8 @@
|
||||
from __future__ import print_function
|
||||
from sphinx.writers.latex import rstdim_to_latexdim
|
||||
|
||||
from util import raises
|
||||
|
||||
|
||||
def test_rstdim_to_latexdim():
|
||||
# Length units docutils supported
|
||||
@ -26,3 +28,7 @@ def test_rstdim_to_latexdim():
|
||||
assert rstdim_to_latexdim('160') is None
|
||||
|
||||
assert rstdim_to_latexdim('160.0em') == '160.0em'
|
||||
|
||||
# unknown values (it might be generated by 3rd party extension)
|
||||
raises(ValueError, rstdim_to_latexdim, 'unknown')
|
||||
assert rstdim_to_latexdim('160.0unknown') == '160.0unknown'
|
||||
|
Loading…
Reference in New Issue
Block a user