latex: Raise error if invalid dimension value

This commit is contained in:
Takeshi KOMIYA committed 2016-06-26 22:55:54 +09:00
1 parent 4bc5a242ce
commit cb00f51328
2 files changed
+8 -1

No files matched your search

+2 -1
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':
+6
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'