orientdb-odm icon indicating copy to clipboard operation
orientdb-odm copied to clipboard

Object value contains '%' sign in class property throws exception in response

Open tomcyr opened this issue 13 years ago • 9 comments

If any object value contains '%' sign in property, response throws Exception because OrientDB REST API cannot parse url. Any ideas except str_replace('%', '', $value) ??

tomcyr avatar Jan 29 '13 01:01 tomcyr

Could you post a small snippet to reproduce the issue please?

nrk avatar Jan 29 '13 07:01 nrk

My Entity Example class:


namespace ConceptIt\SmartShopperBundle\Entity;

use Doctrine\ODM\OrientDB\Mapper\Annotations as ODM;

/**
* @ODM\Document(class="Test")
*/
class Test
{
    /**
     * @ODM\Property(name="@rid", type="string")
     */
    protected $rid;


    /**
     * @ODM\Property(type="string")
     */
    protected $name;


    public function getRid() {
        return $this->rid;
    }

    public function setRid($rid) {
        $this->rid = $rid;

        return $this;
    }


    public function getName() {
        return $this->name;
    }


    public function setName($name) {
        $this->name = $name;

        return $this;
    }
}

and my Action:

     /**
     * @Route("/api/test")
     */
    public function indexAction()
    {
        $manager = $this->container->get('odm');
        $test = new \ConceptIt\SmartShopperBundle\Entity\Test();
        $test->setName('Johny Walker 40%');
        $manager->persist($test);
        var_dump($test);die;
     }

and I have this exception: java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: ""," 500 Internal Server Error - InvalidQueryException

But if I only do:

        $test->setName('Johny Walker 40');

I have dump: object(ConceptIt\SmartShopperBundle\Entity\Test)#407 (2) { ["rid":protected]=> string(5) "#14:0" ["name":protected]=> string(15) "Johny Walker 40" }

So the problem is in '%' sign. I'm using my persist method for manager from https://github.com/doctrine/orientdb-odm/pull/155

tomcyr avatar Jan 31 '13 00:01 tomcyr

Can you check if using urlencode in the toJson method would solve the issue?

odino avatar Jan 31 '13 07:01 odino

I believe this is a bug in OrientDB. It feels just wrong to see a class named URLDecoder throwing an exception like that when we have the % symbol in the JSON payload being sent within the body of the POST request.

I did a quick test using the demo database and the command line curl:

curl --user admin:admin http://127.0.0.1:2480/document/demo -X POST -d '{ "name": "Milano %", "@class": "City" }'

And I get the same error:

java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: "","

If I remove the % symbol then the POST request completes successfully by returning the RID for the new record. The same behaviour can be reproduced when updating an existing record.

Ping @lvca, should we move this one to a new issue on OrientDB?

nrk avatar Jan 31 '13 12:01 nrk

thanks @nrk for the deep analysis :)

odino avatar Jan 31 '13 12:01 odino

Now I'm completely sure this is a bug in OrientDB (and probably a bad one at that) since it seems to treat JSON payload as if it was encoded as application/x-www-form-urlencoded, that's what java.net.URLDecoder is made for after all.

If you try with these two basic examples you will get wrong data stored in the database:

  • curl --user admin:admin http://127.0.0.1:2480/document/demo -X POST -i -H "Accept: application/json" -d '{ "name": "Milano+Roma", "@class": "City" }' The name stored will be Milano Roma since + is the encoded form for the space character.
  • curl --user admin:admin http://127.0.0.1:2480/document/demo -X POST -i -H "Accept: application/json" -d '{ "name": "Milano%24Roma", "@class": "City" }' The name stored will be Milano$Roma since %24 is the encoded form for $.

I will file a bug later.

nrk avatar Feb 05 '13 11:02 nrk

@nrk any news?

odino avatar May 07 '13 19:05 odino

@odino no, I lost track of the time and forgot to provide details on the OrientDB mailing list before filing a bug report :-) Will do that when I'm back at the end of the month.

nrk avatar May 08 '13 07:05 nrk

Be sure to set "Content-Type: application/json" when POSTing. I was running into % errors before when I forgot to do that.

AaronSchulz avatar Dec 21 '14 02:12 AaronSchulz