Skip to content

Commit 66f4e68

Browse files
committed
Merge pull request #1463 from mgreter/bugfix/source-map-inc-paths
Fix source map include paths
2 parents fa8813d + 226178d commit 66f4e68

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

src/file.cpp

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <sys/stat.h>
2323
#include "file.hpp"
2424
#include "context.hpp"
25+
#include "prelexer.hpp"
2526
#include "utf8_string.hpp"
2627
#include "sass2scss.h"
2728

@@ -77,7 +78,14 @@ namespace Sass {
7778
#ifdef _WIN32
7879
if (path.length() >= 2 && isalpha(path[0]) && path[1] == ':') return true;
7980
#endif
80-
return path[0] == '/';
81+
size_t i = 0;
82+
// check if we have a protocol
83+
if (path[i] && Prelexer::is_alpha(path[i])) {
84+
// skip over all alphanumeric characters
85+
while (path[i] && Prelexer::is_alnum(path[i])) ++i;
86+
i = i && path[i] == ':' ? i + 1 : 0;
87+
}
88+
return path[i] == '/';
8189
}
8290

8391
// helper function to find the last directory seperator
@@ -138,7 +146,20 @@ namespace Sass {
138146
while(path.length() > 1 && path.substr(0, 2) == "./") path.erase(0, 2);
139147
while((pos = path.length()) > 1 && path.substr(pos - 2) == "/.") path.erase(pos - 2);
140148

141-
pos = 0; // collapse multiple delimiters into a single one
149+
150+
size_t proto = 0;
151+
// check if we have a protocol
152+
if (path[proto] && Prelexer::is_alpha(path[proto])) {
153+
// skip over all alphanumeric characters
154+
while (path[proto] && Prelexer::is_alnum(path[proto++])) {}
155+
// then skip over the mandatory colon
156+
if (proto && path[proto] == ':') ++ proto;
157+
}
158+
159+
// then skip over start slashes
160+
while (path[proto++] == '/') {}
161+
162+
pos = proto; // collapse multiple delimiters into a single one
142163
while((pos = path.find("//", pos)) != std::string::npos) path.erase(pos, 1);
143164

144165
return path;
@@ -185,6 +206,17 @@ namespace Sass {
185206
std::string absolute_uri = make_absolute_path(uri, cwd);
186207
std::string absolute_base = make_absolute_path(base, cwd);
187208

209+
size_t proto = 0;
210+
// check if we have a protocol
211+
if (uri[proto] && Prelexer::is_alpha(uri[proto])) {
212+
// skip over all alphanumeric characters
213+
while (uri[proto] && Prelexer::is_alnum(uri[proto++])) {}
214+
// then skip over the mandatory colon
215+
if (proto && uri[proto] == ':') ++ proto;
216+
}
217+
218+
if (proto && uri[proto++] == '/') return uri;
219+
188220
#ifdef _WIN32
189221
// absolute link must have a drive letter, and we know that we
190222
// can only create relative links if both are on the same drive

src/parser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,8 @@ namespace Sass {
350350
else error(message, ParserState(message, source, Position(line, column)));
351351
} else if (source) {
352352
if (file) {
353-
ctx.add_source(file, load_path, source);
354-
imp->files().push_back(file);
353+
ctx.add_source(load_path, file, source);
354+
imp->files().push_back(load_path);
355355
} else {
356356
ctx.add_source(load_path, load_path, source);
357357
imp->files().push_back(load_path);

0 commit comments

Comments
 (0)