Code Monkey home page Code Monkey logo

Comments (5)

sumpygump avatar sumpygump commented on May 19, 2024 1

I am on Catalina. I think you are on to something. I believe it just so happens that the character combination I generate introduces a + symbol in the base64 encoded string.

https://ray.so/?colors=midnight&background=true&darkMode=true&padding=64&title=Untitled-1&code=PD9waHAKCnNwcmludGYoIkhlbGxvIDxmZz15ZWxsb3c+JXMiLCAid29ybGQiKTsK

This will fail (because I think the browser interprets the + symbol as a space.

But when I urlencode the base64 encoded value:

https://ray.so/?colors=midnight&background=true&darkMode=true&padding=64&title=Untitled-1&code=PD9waHAKCnNwcmludGYoIkhlbGxvIDxmZz15ZWxsb3c%2BJXMiLCAid29ybGQiKTsK

It works!

Based on that it seems the solution is to replace any + symbols in the generated CODE query parameter with %2B. According to this doc, the only valid output character for a base64 encoded string that would need to be urlencoded is the +, so this primitive approach seems adequate.

I can confirm that editing the script to this on lines 36 and 37 solves it (note I just added a bash replace-all syntax to the $CODE variable here to replace any + with %2B).

CODE=$(pbpaste | base64)
CODE=${CODE//+/%2B}

Let me know if you'd like me to make a pull request for this.

from script-commands.

sumpygump avatar sumpygump commented on May 19, 2024

Follow up on this. I ran a test in order to determine whether base64 was mangling the content before sending it. I added an echo $CODE in the script to see what it was producing. I got the string PD9waHAKCnNwcmludGYoIkhlbGxvIDxmZz15ZWxsb3c+JXMiLCAid29ybGQiKTsK

When I run base64 --decode on it I get the expected results. So the correct string is being sent up to the server:

$ echo PD9waHAKCnNwcmludGYoIkhlbGxvIDxmZz15ZWxsb3c+JXMiLCAid29ybGQiKTsK | base64 --decode
<?php

sprintf("Hello <fg=yellow>%s", "world");

Edit: corrected example output

from script-commands.

thomaspaulmann avatar thomaspaulmann commented on May 19, 2024

Thanks for flagging this. I think the problem is that the open command doesn't properly URL encode the query params. Are you on macOS Big Sur?

from script-commands.

thomaspaulmann avatar thomaspaulmann commented on May 19, 2024

Ah this is brilliant. Please go ahead and submit a PR. Your solutions seems very elegant. Please reference this issue in the PR and then we can close it when it got merged.

Thanks a lot for digging into it. Super appreciated.

from script-commands.

thomaspaulmann avatar thomaspaulmann commented on May 19, 2024

PR merged 👏

from script-commands.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.