Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

Create TXT zone record #31

Open
velgames opened this issue Oct 3, 2014 · 3 comments
Open

Create TXT zone record #31

velgames opened this issue Oct 3, 2014 · 3 comments

Comments

@velgames
Copy link

velgames commented Oct 3, 2014

Hello,

Could you please help me. I am trying to create TXT record using TonicDNS Api, when trying to create it with request body {"records":[{"name":"testtest.ru","type":"TXT","content":"hello","priority":null}]} I got error with message "Record content is not valid. A TXT record must provide a valid quoted string." after adding quotes and escaping them according to JSON escaping rules I got request body {"records":[{"name":"testtest.ru","type":"TXT","content":""hello"","priority":null}]} and response with code BODY_MALFORMED

This makes me believe, that you have some special escaping rules in your JSON parsing library. So how exactly should I form request body for TXT record type.

Thank you.

@LordGaav
Copy link
Member

LordGaav commented Oct 3, 2014

There are no special rules, a simple json_decode is used. Testing it in PHP seems to work fine:

php > $a = json_decode('{"records":[{"name":"testtest.ru","type":"TXT","content":"\"hello\"","priority":null}]}');
php > var_dump($a);
object(stdClass)#1 (1) {
  ["records"]=>
  array(1) {
    [0]=>
    object(stdClass)#2 (4) {
      ["name"]=>
      string(11) "testtest.ru"
      ["type"]=>
      string(3) "TXT"
      ["content"]=>
      string(7) ""hello""
      ["priority"]=>
      NULL
    }
  }
}

As long as the string validates properly using VALID_QUOTES ("^["]{1}(.*)["]{1}$"), it should work.

@velgames
Copy link
Author

velgames commented Oct 6, 2014

Thanks for your response. We have found the source of the error. We set wrong request body type (application/JSON instead of application/json), so code tried to determine proper type by using regexp which apperently doesn't take in consideration possible string escaping.

We also found more crucial thing that might be good to fix. Your validation rules in Validators.class.php doesn't support usage of IDN domains even after you convert them to puny code. Reason is that top level domain name for such domain can be something like .xn--p1ai and your validators don't allow numbers and dashes. Fix is pretty straight forward: we changed all [A-Z]{2,61} to [A-Z0-9-]

@LordGaav
Copy link
Member

LordGaav commented Oct 6, 2014

Can you make a pull request for that based on the develop branch?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants