jsoverson / preprocess

Preprocess HTML, JavaScript, and other files with directives based off custom or ENV configuration
Other
366 stars 80 forks source link

Regex bug in @exec #51

Closed rickihastings closed 9 years ago

rickihastings commented 9 years ago

Hi,

I'm using the following string:

"route": "^androidapps",
    "files": [
        "<!-- @exec resolveAsset('styles/android-apps.css') -->",
        "<!-- @exec resolveAsset('scripts/android-apps.js') -->",
        "<!-- @exec resolveAsset('_feeds/androidApps.config.js') -->"
    ],

But the regex doesn't seem to correctly be picking this up, I can see that the function works and is correctly exposed. When I run this, the output is:

"route": "^androidapps",
    "files": [
        "<!-- @exec resolveAsset('styles/android-apps.css') -->",
        "<!-- @exec resolveAsset('scripts/android-apps.js') -->",
        "_feeds/androidApps.config.js"
    ],

As you can see the last one is replaced, but the first two aren't. I did some digging and it appears some of the regex in https://github.com/jsoverson/preprocess/blob/master/lib/regexrules.js#L10 appears to be incorrect, it's only matching the last rule. I'm not sure if this is something I'm doing wrong though?

rickihastings commented 9 years ago

This appears to be because the string's have a dash in them, why is the regex not matching that?

munkyjunky commented 9 years ago

The problem seems to be with the regex:

html: {
    exec : "<!--[ \t]*@exec[ \t]*(([^\n-]*)[ \t]*\\(([^\n-]*)\\))[ \t]*-->",
}

The regex disallows hyphens in the parameters passed through to the exec function - is there a reason for this?

armandabric commented 9 years ago

No this is imported from the @echo regex. I guess we could allow the -.