Skip to content

fixed bug in less.js where relative url()s were being resvolved based ... #483

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/less/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ less.refreshStyles = loadStyles;

less.refresh(less.env === 'development');


function loadStyles() {
var styles = document.getElementsByTagName('style');
for (var i = 0; i < styles.length; i++) {
Expand Down Expand Up @@ -126,6 +127,7 @@ function loadStyleSheet(sheet, callback, reload, remaining) {
var css = cache && cache.getItem(href);
var timestamp = cache && cache.getItem(href + ':timestamp');
var styles = { css: css, timestamp: timestamp };
var _originalPath = sheet._originalPath || href.replace(/[\w\.-]+$/, '');

// Stylesheets in IE don't always return the full path
if (! /^(https?|file):/.test(href)) {
Expand All @@ -146,9 +148,11 @@ function loadStyleSheet(sheet, callback, reload, remaining) {
} else {
// Use remote copy (re-parse)
try {
var paths = [href.replace(/[\w\.-]+$/, '')];
paths._originalPath = _originalPath;
new(less.Parser)({
optimization: less.optimization,
paths: [href.replace(/[\w\.-]+$/, '')],
paths: paths,
mime: sheet.type
}).parse(data, function (e, root) {
if (e) { return error(e, href) }
Expand Down
2 changes: 1 addition & 1 deletion lib/less/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ if (less.mode === 'browser' || less.mode === 'rhino') {
// We pass `true` as 3rd argument, to force the reload of the import.
// This is so we can get the syntax tree as opposed to just the CSS output,
// as we need this to evaluate the current stylesheet.
loadStyleSheet({ href: path, title: path, type: env.mime }, callback, true);
loadStyleSheet({ href: path, title: path, type: env.mime, _originalPath: paths._originalPath }, callback, true);
};
}

4 changes: 2 additions & 2 deletions lib/less/tree/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ tree.URL = function (val, paths) {
this.attrs = val;
} else {
// Add the base path if the URL is relative and we are in the browser
if (!/^(?:https?:\/\/|file:\/\/|data:)?/.test(val.value) && paths.length > 0 && typeof(window) !== 'undefined') {
val.value = paths[0] + (val.value.charAt(0) === '/' ? val.value.slice(1) : val.value);
if (!/^(?:\/|https?:\/\/|file:\/\/|data:)?/.test(val.value) && paths.length > 0 && typeof(window) !== 'undefined') {
val.value = (paths._originalPath || paths[0]) + val.value;
}
this.value = val;
this.paths = paths;
Expand Down