From 4ebf78b15931e4e01d03caa43923e1095d8d0e0c Mon Sep 17 00:00:00 2001 From: Christian Hofstaedtler Date: Tue, 4 Mar 2014 16:07:36 +0100 Subject: [PATCH] JSON API: strip trailing dots when creating zones Otherwise we end up with example.org. in the DB, when it should have been example.org . --- pdns/ws-auth.cc | 5 +++++ regression-tests.api/test_Zones.py | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/pdns/ws-auth.cc b/pdns/ws-auth.cc index c1261b21fe..ed8ac960b1 100644 --- a/pdns/ws-auth.cc +++ b/pdns/ws-auth.cc @@ -379,6 +379,11 @@ static void apiServerZones(HttpRequest* req, HttpResponse* resp) { if(zonename.empty()) throw ApiException("Zone name empty"); + // strip any trailing dots + while (zonename.substr(zonename.size()-1) == ".") { + zonename.resize(zonename.size()-1); + } + string kind = stringFromJson(document, "kind"); bool exists = B.getDomainInfo(zonename, di); diff --git a/regression-tests.api/test_Zones.py b/regression-tests.api/test_Zones.py index 3055d75c15..3ccee84ac5 100644 --- a/regression-tests.api/test_Zones.py +++ b/regression-tests.api/test_Zones.py @@ -50,6 +50,12 @@ class AuthZones(ApiTestCase): self.assertEquals(data[k], payload[k]) self.assertEquals(data['comments'], []) + def test_CreateZoneTrailingDot(self): + # Trailing dots should not end up in the zone name. + basename = unique_zone_name() + payload, data = self.create_zone(name=basename+'.') + self.assertEquals(data['name'], basename) + def test_CreateZoneWithSymbols(self): payload, data = self.create_zone(name='foo/bar.'+unique_zone_name()) name = payload['name'] -- 2.47.2