|
22 | 22 | #include <sys/stat.h>
|
23 | 23 | #include "file.hpp"
|
24 | 24 | #include "context.hpp"
|
| 25 | +#include "prelexer.hpp" |
25 | 26 | #include "utf8_string.hpp"
|
26 | 27 | #include "sass2scss.h"
|
27 | 28 |
|
@@ -77,7 +78,14 @@ namespace Sass {
|
77 | 78 | #ifdef _WIN32
|
78 | 79 | if (path.length() >= 2 && isalpha(path[0]) && path[1] == ':') return true;
|
79 | 80 | #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] == '/'; |
81 | 89 | }
|
82 | 90 |
|
83 | 91 | // helper function to find the last directory seperator
|
@@ -138,7 +146,20 @@ namespace Sass {
|
138 | 146 | while(path.length() > 1 && path.substr(0, 2) == "./") path.erase(0, 2);
|
139 | 147 | while((pos = path.length()) > 1 && path.substr(pos - 2) == "/.") path.erase(pos - 2);
|
140 | 148 |
|
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 |
142 | 163 | while((pos = path.find("//", pos)) != std::string::npos) path.erase(pos, 1);
|
143 | 164 |
|
144 | 165 | return path;
|
@@ -185,6 +206,17 @@ namespace Sass {
|
185 | 206 | std::string absolute_uri = make_absolute_path(uri, cwd);
|
186 | 207 | std::string absolute_base = make_absolute_path(base, cwd);
|
187 | 208 |
|
| 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 | + |
188 | 220 | #ifdef _WIN32
|
189 | 221 | // absolute link must have a drive letter, and we know that we
|
190 | 222 | // can only create relative links if both are on the same drive
|
|
0 commit comments