Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"PHP Warning: DOMDocument::loadXML()" when sending very looooooong fields #54

Closed
Laurent-Sarrazin opened this issue Mar 20, 2013 · 9 comments
Labels
V2 V2 Client

Comments

@Laurent-Sarrazin
Copy link

Hi,

When creating an account with really long fields value, I get the following error :

PHP Warning:  DOMDocument::loadXML(): Start tag expected, '<' not found in Entity, line: 1 in /home/overblog/public_html/recurly-client-php/lib/recurly/base.php on line 197
PHP Stack trace:
PHP   1. {main}() /home/overblog/public_html/recurly-client-php/recurlyTest.php:0
PHP   2. Recurly_Account->create() /home/overblog/public_html/recurly-client-php/recurlyTest.php:29
PHP   3. Recurly_Resource->_save() /home/overblog/public_html/recurly-client-php/lib/recurly/account.php:33
PHP   4. Recurly_Base->__parseXmlToUpdateObject() /home/overblog/public_html/recurly-client-php/lib/recurly/resource.php:65
PHP   5. DOMDocument->loadXML() /home/overblog/public_html/recurly-client-php/lib/recurly/base.php:197
PHP Fatal error:  Uncaught exception 'Recurly_ValidationError' with message '.' in /home/overblog/public_html/recurly-client-php/lib/recurly/response.php:30
Stack trace:
#0 /home/overblog/public_html/recurly-client-php/lib/recurly/resource.php(67): Recurly_ClientResponse->assertSuccessResponse(Object(Recurly_Account))
#1 /home/overblog/public_html/recurly-client-php/lib/recurly/account.php(33): Recurly_Resource->_save('POST', '/accounts')
#2 /home/overblog/public_html/recurly-client-php/recurlyTest.php(29): Recurly_Account->create()
#3 {main}
  thrown in /home/overblog/public_html/recurly-client-php/lib/recurly/response.php on line 30

Here's the code I used :

$account             = new Recurly_Account(rand(0, 10000000000));
$account->email      = 'laurent@example.com';
$account->first_name = 'Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent ';
$account->last_name  = 'Sarrazin';

$account->create();
@drewish
Copy link

drewish commented Mar 20, 2013

So looked and we only store 255 character first and last names. We don't document that on http://docs.recurly.com/api/accounts, which is an oversight that I'll bring up with the team.

I ran your sample code locally and it created a an account for me but truncated the name down 255 characters (so only "Laurent"s). Can you provide any additional detail that would help me reproduce this?

@Laurent-Sarrazin
Copy link
Author

Yep sorry. My example indeed works.
Just double the length of the string and you'll get the warning.

@drewish
Copy link

drewish commented Mar 20, 2013

Great, seeing it now. I'll dig into this.

@drewish
Copy link

drewish commented Mar 20, 2013

It was brought to my attention that we do document the lengths on http://docs.recurly.com/api/accounts#create-account I'm curious why we're not able to throw an accurate error though.

@Laurent-Sarrazin
Copy link
Author

I investigated myself and the issue is that the server send 2 headers :

HTTP/1.1 100 Continue

HTTP/1.1 201 Created
Server: blackhole
Date: Wed, 20 Mar 2013 15:31:11 GMT
Content-Type: application/xml; charset=utf-8
Transfer-Encoding: chunked
Connection: close
Content-Language: en-US
ETag: "8c6ce55120e7a759a1f0cb4fcac4ebf8"
Location: https://api.recurly.com/v2/accounts/2607108494
Cache-Control: max-age=0, private, must-revalidate
Set-Cookie: account_credentials=****; domain=.recurly.com; path=/
Set-Cookie: _recurly_session=****; domain=.recurly.com; path=/; secure; HttpOnly
X-Runtime: 0.141334

<?xml version="1.0" encoding="UTF-8"?>
<account href="https://api.recurly.com/v2/accounts/2607108494">
  <adjustments href="https://api.recurly.com/v2/accounts/2607108494/adjustments"/>
  <invoices href="https://api.recurly.com/v2/accounts/2607108494/invoices"/>
  <subscriptions href="https://api.recurly.com/v2/accounts/2607108494/subscriptions"/>
  <transactions href="https://api.recurly.com/v2/accounts/2607108494/transactions"/>
  <account_code>2607108494</account_code>
  <state>active</state>
  <username nil="nil"></username>
  <email>laurent@example.com</email>
  <first_name>Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent Laurent</first_name>
  <last_name>Sarrazin</last_name>
  <company_name nil="nil"></company_name>
  <accept_language nil="nil"></accept_language>
  <hosted_login_token>***</hosted_login_token>
  <created_at type="datetime">2013-03-20T15:31:11Z</created_at>
</account> 

which is the expected behavior as the data length is too long to be sent in a single shot.
But when the client tries to parse the response with

list($header, $body) = explode("\r\n\r\n", $response, 2);

It gets the 201 headers instead of the xml body.

@Laurent-Sarrazin
Copy link
Author

It seems that for a "bare" account (without billing info), there is no check of the character length. I've been able to create an account with a very long first name. But once in the recurly app, the 50 characters limitation prevents me from editing and saving the account.
Screen Shot 2013-03-20 at 10 55 13 AM

I opened a support ticket for this issue as it's more an api issue than a client one.

@drewish
Copy link

drewish commented Mar 20, 2013

Yeah as you noted we actually enforce the limit in the UI but not on the API. So that's one issue.

The long/error response parsing seems to be another. I tried running the longer version against an instance of the API on my laptop and didn't have any issue so I think it might be some rewriting by our load balancer or proxy. We could probably add some work around code to the client but I'm not sure that's the right fix.

@Laurent-Sarrazin
Copy link
Author

I agree. My "fix" is more a workaround than anything else.

@drewish
Copy link

drewish commented May 8, 2014

I'd totally forgotten about this issue but we finally addressed in in #88.

@drewish drewish closed this as completed May 8, 2014
@bhelx bhelx added the V2 V2 Client label Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
V2 V2 Client
Projects
None yet
Development

No branches or pull requests

3 participants