latex: Raise error if invalid dimension value

This commit is contained in:
Takeshi KOMIYA 2016-06-26 13:31:07 +09:00
parent 4bc5a242ce
commit cb00f51328
2 changed files with 8 additions and 1 deletions

View File

@ -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':

View File

@ -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'