Mydayyy / pbcli

pbcli is a command line client which allows to upload and download pastes from privatebin directly from the command line.
MIT License
10 stars 4 forks source link

pbcli not working with PrivateBin using local path in URL #1

Closed matwei closed 12 months ago

matwei commented 12 months ago

Hello,

while testing I found that pbcli did not work with a PrivateBin instance like https://example.org/localpath/, that means with a local path added to the URL.

I investigated this further and found a workaround for this problem with the following change:

$ git diff
diff --git a/src/api.rs b/src/api.rs
index a48408a..b8d530c 100644
--- a/src/api.rs
+++ b/src/api.rs
@@ -17,7 +17,7 @@ impl API {
     pub fn new(mut url: Url, opts: Opts) -> Self {
         url.set_fragment(None);
         url.set_query(None);
-        url.set_path("");
+//        url.set_path("");
         Self { base: url, opts }
     }

@@ -118,4 +118,4 @@ impl API {
             s => Err(PasteError::UnknownPasteStatus(s)),
         }
     }
-}
\ No newline at end of file
+}
diff --git a/src/main.rs b/src/main.rs
index b5a78f9..a63a7bd 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -110,7 +110,7 @@ fn handle_post(opts: &Opts) -> PbResult<()> {
         std::io::stdout().write_all(serde_json::to_string(&res)?.as_bytes())?;
     } else {
         let mut url = opts.get_url().clone();
-        url.set_path("");
+//        url.set_path("");
         url.set_query(Some(&res.id));
         url.set_fragment(Some(&res.bs58key));
         std::io::stdout().write_all(url.to_string().as_bytes())?;

This works with URLs like https://example.org/localpath/ but fails with https://example.org/localpath (i.e. without the slash at the end). So you probably want to find a more resilient solution.

Mydayyy commented 12 months ago

Greetings,

thank you very much for this report. I actually did not test that use-case. I will look into this and work on a fix.

Best Regards Mydayyy

Mydayyy commented 12 months ago

Greetings,

this should be fixed by 8d4cdf6a66351d9d0901386a3d15083bed2510a0. I will do some more testing on the weekend and if no further issues appear I will proceed to create a release here and on the AUR.

Best Regards Mydayyy

matwei commented 12 months ago

Hi,

I just tested 8d4cdf6. This works fine with a local path (with and without a slash at the end).

Thanks for your work, Mathias

Mydayyy commented 12 months ago

Greetings,

thank you for the re-test. I too was not able to find any regressions.

Released as v2.2.1 here and on the AUR

Best Regards Mydayyy