GithubHelp home page GithubHelp logo

Comments (7)

DarthSim avatar DarthSim commented on July 23, 2024 1

Hey @Ross-Hunter!

watermark-text accepts text in the Pango markup. Since it is an HTML-like language, it has the same special characters: <, >, and &. All you need is to replace them with &lt;, &gt;, and &amp; respectively, or just use an HTML-escaping function from your language. Guess it is worth mentioning in the docs 🤔

from imgproxy.

mstaack avatar mstaack commented on July 23, 2024

do you use correct encoding?

show me your url please

from imgproxy.

Joe-Degler avatar Joe-Degler commented on July 23, 2024

Stepping in for ross here.

I think we should've filed this issue in imgproxy.rb as that's what we're using here.
https://github.com/imgproxy/imgproxy.rb

I think our default assumption would've been that the gem would take care to either make sure the watermark_text was compliant by encoding it correctly, or raised an error directly, instead of returning an URL. In its current state, the issue was not obvious to figure out.

from imgproxy.

DarthSim avatar DarthSim commented on July 23, 2024

I don't think it's really possible. A user may want to use the Pango markup in the watermark_text value, and if the gem escapes every watermark_text value, it would ruin the markup.

The other way is to try to predict if the user tries to use markup or not. This will most probably lead to more confusion.

The third way is to try to parse the watermark_text value and raise an error if the parsing fails. There we'll need something like Nokogiri or Ox just to check the value of a single option. Not a good idea IMHO. Also, we don't check values in imgproxy.rb at all.

The fourth way is to add an argument to the watermark_text option that disables the Pango markup. This is doable and, probably, is a good idea. But the markup will be enabled by default anyway since this is the current behavior, so the problem of "the issue was not obvious to figure out" won't be solved.

And last but not least: you can wrap the watermark_text value with CGI::escapeHTML right in your code, which will solve the problem completely 🙂

from imgproxy.

Ross-Hunter avatar Ross-Hunter commented on July 23, 2024

Hey @Ross-Hunter!

watermark-text accepts text in the Pango markup. Since it is an HTML-like language, it has the same special characters: <, >, and &. All you need is to replace them with &lt;, &gt;, and &amp; respectively, or just use an HTML-escaping function from your language. Guess it is worth mentioning in the docs 🤔

That was the issue. I did not see anything in the docs about special characters in watermark text.

I can tell that imgproxy.rb is properly base64 encoding the value, but if that value contains an ampersand, then imgproxy (go) returns a 500 -- however if I CGI.escapeHTML(watermark_text) in ruby then it works as intended.

I suppose imgproxy.rb could handle that for folks, but I think you would still want to document the Pango markup behavior here for people not using imgproxy.rb.

Thanks for the help @DarthSim!

from imgproxy.

DarthSim avatar DarthSim commented on July 23, 2024

No problem! I'll definitely add a warning about this to the docs.

from imgproxy.

Ross-Hunter avatar Ross-Hunter commented on July 23, 2024

And of course, now I find it in the docs 🤦

https://docs.imgproxy.net/features/watermark#text-watermarks

I think I kept reading this and not quite registering that you must use pango markup to support special characters.

from imgproxy.

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.