Skip to content

Commit

Permalink
[BUGFIX] Add fix for source-maps (Fix-Up PR sass#591)
Browse files Browse the repository at this point in the history
- Remove line-breaks in Base64 encoded string
- Actually embed the source-map json in data-url
- Include original source in sources array
  • Loading branch information
mgreter committed Nov 4, 2014
1 parent 18b0d9b commit c33353d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 12 deletions.
7 changes: 0 additions & 7 deletions cencode.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ For details, see http://sourceforge.net/projects/libb64

#include "b64/cencode.h"

const int CHARS_PER_LINE = 72;

void base64_init_encodestate(base64_encodestate* state_in)
{
state_in->step = step_A;
Expand Down Expand Up @@ -73,11 +71,6 @@ int base64_encode_block(const char* plaintext_in, int length_in, char* code_out,
*codechar++ = base64_encode_value(result);

++(state_in->stepcount);
if (state_in->stepcount == CHARS_PER_LINE/4)
{
*codechar++ = '\n';
state_in->stepcount = 0;
}
}
}
/* control should not reach here */
Expand Down
7 changes: 4 additions & 3 deletions context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,14 @@ namespace Sass {
return result;
}

string Context::format_source_mapping_url(const string& file) const
string Context::format_source_mapping_url(const string& file)
{
string url = resolve_relative_path(file, output_path, cwd);
if (source_map_embed) {
base64::encoder E;
istringstream is( sources[0] );
string map = source_map.generate_source_map(*this);
istringstream is( map );
ostringstream buffer;
base64::encoder E;
E.encode(is, buffer);
url = "data:text/css;base64," + buffer.str();
url.erase(url.size() - 1);
Expand Down
2 changes: 1 addition & 1 deletion context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ namespace Sass {

private:
void add_source(const string &load_path, const string &abs_path, const char* contents);
string format_source_mapping_url(const string& file) const;
string format_source_mapping_url(const string& file);
string get_cwd();

string cwd;
Expand Down
2 changes: 1 addition & 1 deletion source_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace Sass {

JsonNode *json_contents = json_mkarray();
if (include_sources) {
for (size_t i = 1; i < source_index.size(); ++i) {
for (size_t i = 0; i < source_index.size(); ++i) {
const char *content = sources[source_index[i]];
JsonNode *json_content = json_mkstring(content);
json_append_element(json_contents, json_content);
Expand Down

0 comments on commit c33353d

Please sign in to comment.