appwrite icon indicating copy to clipboard operation
appwrite copied to clipboard

🐛 Bug Report: Document creation failed when using url attribute

Open Rinma opened this issue 3 years ago • 16 comments

👟 Reproduction steps

When I create a new collection with an url attribute and try to create a new document in it, on the web editor or as api request, with this url:

https://www.amazon.de/AMAZONAS-Hängemattengestell-RockStone-größenverstellbar-270-330/dp/B005HGW6A4

I get an error message: Invalid document structure: Attribute "buy_url" has invalid format. Value must be a valid URL

👍 Expected behavior

It should create the document with the url attribute

👎 Actual Behavior

It can't create the document when I use an url attribute.

🎲 Appwrite version

Version 0.15.x

💻 Operating system

Linux

🧱 Your Environment

I have a Hetzner root Server with debian Linux and run appwrite with docker-compose instead of the docker command.

👀 Have you spent some time to check if this issue has been raised before?

  • [X] I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

Rinma avatar Aug 12 '22 21:08 Rinma

Kindly share your code.

bliyscom avatar Aug 13 '22 11:08 bliyscom

Sure, here the error in the web editor and the minimal code:

image

const db = new Databases(
      this.client,
      "62f7b51b49389fe3a0a6"
    );

db.createDocument(
      "62f7b5201284ef2ef2f7",
      "NewDocumentId",
      {
        url: 'https://www.amazon.de/AMAZONAS-Hängemattengestell-RockStone-größenverstellbar-270-330/dp/B005HGW6A4'
      },
      ['role:all'],
      [`user:62f3eb06921b14c925a7`]
    );

And this code gives this error

{
    "message": "Invalid document structure: Attribute \"url\" has invalid format. Value must be a valid URL",
    "code": 400,
    "type": "document_invalid_structure",
    "version": "0.15.3"
}

The collection attributes are these:

image

Rinma avatar Aug 13 '22 15:08 Rinma

I had a thought and tried it https://www.amazon.de/AMAZONAS-Hngemattengestell-RockStone-grenverstellbar-270-330/dp/B005HGW6A4 <- this would be a valid URL. So, the regex or whatever checks in appwrite if it is a valid URL, seams to have problems with handling German Umlaute "äöüß" in the path part of the URL.

Rinma avatar Aug 13 '22 15:08 Rinma

Good guess. Although, it would be difficult to create a regex rule that supports all languages. So i suggest you keep sanitizing the url for special letters for now. You can equally just paste the url into the browser address bar, then copy paste it back into the field. It should already be translated.

bliyscom avatar Aug 13 '22 15:08 bliyscom

@Rinma, thank you for raising this issue! 🙏 . We use PHP's filter_var() to validate URLs:

https://github.com/appwrite/appwrite/blob/5b4a3805bf7a1ee54cb562fd525dd471069a4cdd/src/Appwrite/Network/Validator/URL.php#L52

It looks like it doesn't handle some special characters. I'll talk to the team about how we can improve this!

stnguyen90 avatar Aug 13 '22 20:08 stnguyen90

hey @Rinma I want to contribute to this issue . Can you please allow me ?

aakash-gorai avatar Aug 18 '22 15:08 aakash-gorai

@aakash-kumar-gorai, go for it! Please make sure to add test cases and validate the URL is correct when inserted into the Database and when it is retrieved. 🙏

stnguyen90 avatar Aug 18 '22 16:08 stnguyen90

@stnguyen90 there's no update from @aakash-kumar-gorai can you assign it to me?

MahendraBishnoi29 avatar Sep 12 '22 15:09 MahendraBishnoi29

Sure, @MahendraBishnoi29!

stnguyen90 avatar Sep 12 '22 20:09 stnguyen90

also @stnguyen90 can guide me where to make changes because it's my first contribution here :)

MahendraBishnoi29 avatar Sep 13 '22 02:09 MahendraBishnoi29

@MahendraBishnoi29, see my previous comment.

stnguyen90 avatar Sep 18 '22 14:09 stnguyen90

@Rinma, thank you for raising this issue! 🙏 . We use PHP's filter_var() to validate URLs:

https://github.com/appwrite/appwrite/blob/5b4a3805bf7a1ee54cb562fd525dd471069a4cdd/src/Appwrite/Network/Validator/URL.php#L52

It looks like it doesn't handle some special characters. I'll talk to the team about how we can improve this!

@stnguyen90 are you talking about this one? 🤔

MahendraBishnoi29 avatar Sep 18 '22 15:09 MahendraBishnoi29

@stnguyen90 are you talking about this one? 🤔

Yes, @MahendraBishnoi29.

stnguyen90 avatar Sep 18 '22 15:09 stnguyen90

@stnguyen90 are you talking about this one? 🤔

Yes, @MahendraBishnoi29.

sorry, I'm not much familiar with PHP so still didn't get it? 😔

MahendraBishnoi29 avatar Sep 18 '22 15:09 MahendraBishnoi29

@MahendraBishnoi29, sounds like you'll need to find some resources on PHP. If this is too difficult, let me know and I'll unassign you from this issue.

stnguyen90 avatar Sep 18 '22 15:09 stnguyen90

@stnguyen90 ok

MahendraBishnoi29 avatar Sep 19 '22 11:09 MahendraBishnoi29

@MahendraBishnoi29, any progress on this or should I unassign you?

stnguyen90 avatar Sep 27 '22 20:09 stnguyen90

@MahendraBishnoi29, any progress on this or should I unassign you?

yes go ahead.

MahendraBishnoi29 avatar Sep 28 '22 02:09 MahendraBishnoi29

@stnguyen90 can you assign it to me ?

Sooraj-s-98 avatar Sep 30 '22 06:09 Sooraj-s-98

@Sooraj-s-98 Since this is an Hacktoberfest labeled issue, please ask for reassignment when the hacktoberfest starts officially😄

2002Bishwajeet avatar Sep 30 '22 06:09 2002Bishwajeet

Hey @Rinma @stnguyen90, I would like to work on this if its not yet done!

SaurabhNandy avatar Sep 30 '22 21:09 SaurabhNandy

@stnguyen90 can you assign me ? Please check PR

Sooraj-s-98 avatar Sep 30 '22 22:09 Sooraj-s-98

@SaurabhNandy, thanks for your interest! 🙏 Happy hacking!

@Sooraj-s-98, we're assigning people on a first come first serve basis after hacktoberfest starts. If @SaurabhNandy isn't able to complete the issue, we're reassign accordingly. I'm the meantime, you can look for another hacktoberfest issue via our website.

stnguyen90 avatar Oct 02 '22 01:10 stnguyen90

@stnguyen90 can you check my PR ?

Sooraj-s-98 avatar Oct 03 '22 15:10 Sooraj-s-98