From: Christian Hofstaedtler Date: Tue, 4 Mar 2014 15:07:36 +0000 (+0100) Subject: JSON API: strip trailing dots when creating zones X-Git-Tag: rec-3.6.0-rc1~150^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F1316%2Fhead;p=thirdparty%2Fpdns.git 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 . --- 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']