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

@import directive in an already @import'd file uses full url with hash as base #134

Closed
dbergey opened this issue Nov 1, 2010 · 5 comments

Comments

@dbergey
Copy link
Contributor

dbergey commented Nov 1, 2010

My page's url looks like this, with a hash in the middle: http://mysite.com/#/controller/function/

In a <style> tag on the main page, I have (which works fine):

@import "/assets/main.less";

Inside main.less is another @import without a path:

@import "include.less"

The browser requests it as "http://mysite.com/#/controller/function/include.less", disregarding the hash. I have discovered that if I comment out the block:

// Stylesheets in IE don't always return the full path
if (! /^(https?|file):/.test(href)) {
    href = url.slice(0, url.lastIndexOf('/') + 1) + href;
}

...it works, and I have worked around it for now in Safari by adding a second condition thusly:

// Stylesheets in IE don't always return the full path
if (! /^(https?|file):/.test(href) && /msie/.test(navigator.userAgent)) {
    href = url.slice(0, url.lastIndexOf('/') + 1) + href;
}

...but that is of course not a good long-term solution, and probably doesn't fix the issue in IE.

Being unfamiliar with the less.js codebase, I'm not sure what or where the problem is. Help?

@neonstalwart
Copy link
Contributor

it should probably work to just change the url like this when it's declared:
var url = window.location.href.replace(/^([^?#]+).*$/, '$1');

@dbergey
Copy link
Contributor Author

dbergey commented Nov 1, 2010

Did it simpler:

var url = window.location.href.replace(/#.*$/, '');

Still would be nice to have it in the official build.

@neonstalwart
Copy link
Contributor

yours is simpler... but needs to account for '?' in the url which will have the same problem as '#' ;)
var url = window.location.href.replace(/[?#].*$/, '');

Still would be nice to have it in the official build.

just fork, modify, and add a pull request. sometimes it takes a while for a response but @cloudhead eventually responds.

@dbergey
Copy link
Contributor Author

dbergey commented Nov 1, 2010

I realized that after I posted it. Shall fork.

jamesfoster pushed a commit to jamesfoster/less.js that referenced this issue May 16, 2011
…nd url portions thereafter as part of the base url.
yhahn referenced this issue in mapbox/carto Aug 4, 2011
…rl portions thereafter as part of the base url.
@neonstalwart neonstalwart mentioned this issue May 15, 2012
@lukeapage
Copy link
Member

The pull request to fix this bug by @dbergey was committed.. therefore this particular bug should be fixed.. ? Any disagreements?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants