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

Firefox URI-encodes Tim tags within DOM tags #9

Open
kfancy opened this issue Nov 15, 2011 · 0 comments
Open

Firefox URI-encodes Tim tags within DOM tags #9

kfancy opened this issue Nov 15, 2011 · 0 comments

Comments

@kfancy
Copy link

kfancy commented Nov 15, 2011

Firefox is URI-encoding Tim tags used within DOM tags as part of the tag itself.

Examples:
<a href="{{foo.link}}">{{foo.text}}</a>
<img src="{{foo.img}}" />

Using Firebug, you can see that Firefox conveniently converts the tags to:
<a href="%7B%7Bfoo.link%7D%7D">{{foo.text}}</a>
<img src="%7B%7Bfoo.img%7D%7D" />

In short, this problem requires running the Regular Expression replace function twice if the browser is Firefox. During the second run, the tags should be encoded using encodeURIComponent() inside the regex pattern.

Fix I've implemented:
I'm using Mootools, so my solution is Mootools-centric. Also, I extracted the core Tim lite functionality and rolled it into a component for my own templating system so it's not completely Tim-ready, but here's the idea:

    tim_start: '{{',
    tim_end: '}}',
    tim_path: '[A-Za-z0-9_][\\.A-Za-z0-9_]*',

    tim_tpl: function(tpl) {
        var pattern = new RegExp(this.tim_start + "\\s*("+ this.tim_path +")\\s*" + this.tim_end, "gi");

        tpl.set('html',tpl.get('html').replace(pattern, function(tag, path){
                // tag = entire {{tag}}
                return this.resolve_ref(path);
            }.bind(this)));

        if (Browser.firefox) {
            pattern = new RegExp(encodeURIComponent(this.tim_start) + "\\s*("+ this.tim_path +")\\s*" + encodeURIComponent(this.tim_end), "gi");
            tpl.set('html',tpl.get('html').replace(pattern, function(tag, path){
                    // tag = entire {{tag}}
                    return this.resolve_ref(path);
                }.bind(this)));
        }

        return tpl;
    },
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant