Make sure that values are IP addresses/ranges

This commit adds safeguarding for invalid IP address/range values.
This commit is contained in:
Jan Dittberner 2016-05-05 11:13:53 +02:00
parent c1caa62c5d
commit 0dafa28150
2 changed files with 16 additions and 0 deletions

View file

@ -28,6 +28,11 @@ Contributors
Changes Changes
======= =======
0.2.1 - to be released
----------------------
* fix handling of invalid IP address/range values
0.2.0 - 2016-05-04 0.2.0 - 2016-05-04
------------------ ------------------

View file

@ -52,6 +52,17 @@ class IPXRefRole(XRefRole):
super(IPXRefRole, self).__init__( super(IPXRefRole, self).__init__(
innernodeclass=innernodeclass, **kwargs) innernodeclass=innernodeclass, **kwargs)
def __call__(self, typ, rawtext, text, lineno, inliner,
options={}, content=[]):
try:
Network(text)
except ValueError as e:
env = inliner.document.settings.env
env.warn(env.docname, "invalid ip address/range %s" % text, lineno)
return [nodes.literal(text, text), []]
return super(IPXRefRole, self).__call__(
typ, rawtext, text, lineno, inliner, options, content)
def process_link(self, env, refnode, has_explicit_title, title, target): def process_link(self, env, refnode, has_explicit_title, title, target):
domaindata = env.domaindata['ip'] domaindata = env.domaindata['ip']
domaindata[self.method][target] = (target, refnode) domaindata[self.method][target] = (target, refnode)