From a17f55a6a9debe8d20019d34e8f776fe17f001e5 Mon Sep 17 00:00:00 2001
From: Jan Dittberner <jan@dittberner.info>
Date: Thu, 5 May 2016 10:44:57 +0200
Subject: [PATCH 1/5] Bump version

---
 jandd/sphinxext/ip.py | 2 +-
 setup.py              | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/jandd/sphinxext/ip.py b/jandd/sphinxext/ip.py
index 0c71bda..a236356 100644
--- a/jandd/sphinxext/ip.py
+++ b/jandd/sphinxext/ip.py
@@ -23,7 +23,7 @@ from sphinx.locale import l_
 from sphinx.roles import XRefRole
 from sphinx.util.nodes import make_refnode
 
-__version__ = '0.2.0'
+__version__ = '0.2.1'
 
 
 def ip_object_anchor(typ, path):
diff --git a/setup.py b/setup.py
index b992734..4a22ff9 100644
--- a/setup.py
+++ b/setup.py
@@ -2,7 +2,7 @@
 
 from setuptools import setup, find_packages
 
-version = '0.2.0'
+version = '0.2.1'
 
 with open('README.rst') as readme:
     description = readme.read() + "\n\n"

From c1caa62c5d3c3cb34373e618a3bc8b883dc05eaf Mon Sep 17 00:00:00 2001
From: Jan Dittberner <jan@dittberner.info>
Date: Thu, 5 May 2016 10:47:35 +0200
Subject: [PATCH 2/5] Add test data that breaks IP address parsing

---
 .gitignore               | 1 +
 tests/root/testpage2.rst | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/.gitignore b/.gitignore
index ef30f6c..d096524 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,4 @@ dist/
 .coverage
 htmlcov/
 build/
+_build/
diff --git a/tests/root/testpage2.rst b/tests/root/testpage2.rst
index f7c3351..f6ecf35 100644
--- a/tests/root/testpage2.rst
+++ b/tests/root/testpage2.rst
@@ -6,3 +6,6 @@ This page contains IP addresses :ip:v4:`127.0.0.1`, :ip:v4:`192.168.0.1` and
 
 There is also :ip:v6range:`2001:dada:b001::/64` and
 :ip:v4range:`172.16.0.0/24`.
+
+The extension should also handle malformed things like :ip:v4:`<IP>`,
+:ip:v6:`<IP6>`, :ip:v4range:`<IPR>` and :ip:v6range:`<IPR6>` properly.

From 0dafa2815000e24e9d0e6b9f03837aaa2be3839f Mon Sep 17 00:00:00 2001
From: Jan Dittberner <jan@dittberner.info>
Date: Thu, 5 May 2016 11:13:53 +0200
Subject: [PATCH 3/5] Make sure that values are IP addresses/ranges

This commit adds safeguarding for invalid IP address/range values.
---
 README.rst            |  5 +++++
 jandd/sphinxext/ip.py | 11 +++++++++++
 2 files changed, 16 insertions(+)

diff --git a/README.rst b/README.rst
index 97ccd17..563d9f7 100644
--- a/README.rst
+++ b/README.rst
@@ -28,6 +28,11 @@ Contributors
 Changes
 =======
 
+0.2.1 - to be released
+----------------------
+
+* fix handling of invalid IP address/range values
+
 0.2.0 - 2016-05-04
 ------------------
 
diff --git a/jandd/sphinxext/ip.py b/jandd/sphinxext/ip.py
index a236356..7582159 100644
--- a/jandd/sphinxext/ip.py
+++ b/jandd/sphinxext/ip.py
@@ -52,6 +52,17 @@ class IPXRefRole(XRefRole):
         super(IPXRefRole, self).__init__(
             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):
         domaindata = env.domaindata['ip']
         domaindata[self.method][target] = (target, refnode)

From 01c31e9263ac04f449db22ef455114e72fd4f07b Mon Sep 17 00:00:00 2001
From: Jan Dittberner <jan@dittberner.info>
Date: Thu, 5 May 2016 11:34:27 +0200
Subject: [PATCH 4/5] Implement proper clear_doc method for IPDomain

This commit replaces the dummy clear_doc method in
jandd.sphinxext.ip.IPDomain with a proper implementation that clears
document related items from the domain data dictionary.
---
 README.rst            |  1 +
 jandd/sphinxext/ip.py | 17 ++++++++++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/README.rst b/README.rst
index 563d9f7..04f5977 100644
--- a/README.rst
+++ b/README.rst
@@ -32,6 +32,7 @@ Changes
 ----------------------
 
 * fix handling of invalid IP address/range values
+* implement a proper clear_doc method for the ip domain
 
 0.2.0 - 2016-05-04
 ------------------
diff --git a/jandd/sphinxext/ip.py b/jandd/sphinxext/ip.py
index 7582159..fe25208 100644
--- a/jandd/sphinxext/ip.py
+++ b/jandd/sphinxext/ip.py
@@ -191,7 +191,22 @@ class IPDomain(Domain):
     }
 
     def clear_doc(self, docname):
-        pass
+        to_remove = []
+        for key, value in self.data['v4range'].items():
+            if docname == value[0]:
+                to_remove.append(key)
+        for key in to_remove:
+            del self.data['v4range'][key]
+
+        to_remove = []
+        for key, value in self.data['v6range'].items():
+            if docname == value[0]:
+                to_remove.append(key)
+        for key in to_remove:
+            del self.data['v6range'][key]
+        self.data['ips'] = [
+            item for item in self.data['ips'] if item['docname'] != docname
+        ]
 
     def resolve_xref(self, env, fromdocname, builder, typ, target, node,
                      contnode):

From a463ee0a0d93d2e601e4a94c3ca914ef22574ad2 Mon Sep 17 00:00:00 2001
From: Jan Dittberner <jan@dittberner.info>
Date: Thu, 5 May 2016 11:37:52 +0200
Subject: [PATCH 5/5] Set release date in change log

---
 README.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/README.rst b/README.rst
index 04f5977..d2f696b 100644
--- a/README.rst
+++ b/README.rst
@@ -28,8 +28,8 @@ Contributors
 Changes
 =======
 
-0.2.1 - to be released
-----------------------
+0.2.1 - 2016-05-05
+------------------
 
 * fix handling of invalid IP address/range values
 * implement a proper clear_doc method for the ip domain