Code Monkey home page Code Monkey logo

Comments (7)

Robert-Kolmos avatar Robert-Kolmos commented on September 26, 2024 2

Hey all, I'd like to take a crack at this one.

from templ.

joerdav avatar joerdav commented on September 26, 2024 2

I think we want to avoid making users use backticks. Someone should be able to copy/paste HTML without amendments into a templ file.

from templ.

a-h avatar a-h commented on September 26, 2024 1

Nice. I'd love a PR on it. Crack on mate! 😀

If you don't have time, just say, and I'll get to it.

from templ.

a-h avatar a-h commented on September 26, 2024

Please provide a reproducible example, with instructions of what to run, and explain what you expect to happen, and what is actually happening.

from templ.

zmzlois avatar zmzlois commented on September 26, 2024

so in the repo https://github.com/zmzlois/templ-repro I have provided two example, where regular expression is working in test.ts , but it will cause parsing failure in templ

from templ.

joerdav avatar joerdav commented on September 26, 2024

I understand the issue. This isn't related directly to regex but how we represent string attributes.

In HTML, this is a valid attribute: pattern="/^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/i"
Or a minimal reprod, this is valid HTML too: pattern="\s"

HTML spec states that an attribute value can contain anything except for a " or a &. So an unescaped \ is in-fact valid. But, we generate these strings directly to Go strings without escaping, where a backslash on it's own is invalid.

So I believe that the solution here, is to Go string escape constant string attributes(replace \ with \\). We shouldn't change the behaviour of expressions, since they are go strings, and follow go escaping rules.

from templ.

Robert-Kolmos avatar Robert-Kolmos commented on September 26, 2024

Question for the group here. If we start escaping constant string attributes I believe that will be a breaking change because someone previously could have done

templ input() {
    <input pattern="\\s" /> 
}

which would have resulted in <input pattern="\s">. With escaping this would become <input pattern="\\s">

I've got a branch here that demonstrates how to make the current state of the project generate the (https?|ftp):\/\/[^\s/$.?#].[^\s]* pattern from the start of this thread.

Do we want to avoid making users use a backtick string like this or is this an acceptable workaround?

from templ.

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.