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

Implement URI encoding and decoding for filenames #9

Closed
andy5995 opened this issue Sep 15, 2020 · 5 comments
Closed

Implement URI encoding and decoding for filenames #9

andy5995 opened this issue Sep 15, 2020 · 5 comments
Assignees
Milestone

Comments

@andy5995
Copy link
Member

When the absolute path and filename is written to a .trashinfo file, the string should be encoded per RFC2396.

Conversely, the string will need to be decoded when restoring the file (#5).

This already happens for the C version of rmw. Here are the relevant functions that it uses:

is_unreserved()
https://github.com/theimpossibleastronaut/rmw/blob/94d19a0017b4d749a03baf6277f4f983a1dcfb3a/src/utils_rmw.c#L190-L220

escape_url()
https://github.com/theimpossibleastronaut/rmw/blob/94d19a0017b4d749a03baf6277f4f983a1dcfb3a/src/utils_rmw.c#L223-L280

unescape_url()
https://github.com/theimpossibleastronaut/rmw/blob/94d19a0017b4d749a03baf6277f4f983a1dcfb3a/src/utils_rmw.c#L283-L336

@andy5995 andy5995 added this to the v0.1.0 milestone Sep 15, 2020
This was referenced Sep 15, 2020
andy5995 added a commit that referenced this issue Sep 15, 2020
@andy5995
Copy link
Member Author

I just found there's a library developed by @johnstonskj that may work for this ticket.

rdftk_iri

andy5995 added a commit that referenced this issue Sep 15, 2020
@andy5995
Copy link
Member Author

andy5995 commented Sep 15, 2020

I've applied a patch that uses the pct-str library. It follows the RFC 3986. It shows that 2396 has been deprecated.

The Freedesktop Trash spec still shows RFC 2396 as the required spec for path encoding, but I'm guessing that info will be updated.

One difference with the 3986 spec is that slashes are escaped now.

Here's the resulting Trash Info file with the patch applied, after I run rmwrs 'foo bar!'

[Trash Info]
Path=%2Fhome%2Fandy%2Fsrc%2Ftheimpossibleastronaut%2Frmwrs%2Ffoo bar%21
DeletionDate=2020-09-15T14:25:14

@andy5995
Copy link
Member Author

I think best to stick with the Freedesktop trash spec, using 2396. We can still use the pct_str library; there's an example here for customizing the reserved and unreserved characters:

https://docs.rs/pct-str/1.1.0/pct_str/

@andy5995
Copy link
Member Author

I think best to forget about using a library and just convert to Rust the three functions mentioned in the first post.

@andy5995
Copy link
Member Author

andy5995 commented Oct 1, 2020

Resolved in #10

Thank you @Jammyjamjamman !

@andy5995 andy5995 closed this as completed Oct 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants