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

Don't raise error when template is empty #31

Merged
merged 2 commits into from
Jan 11, 2016
Merged
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
2 changes: 2 additions & 0 deletions lib/sassc/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def initialize(template, options = {})
end

def render
return @template if @template.empty?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to replace it with return '' if @template.empty?? It may seem the same but it isn't. With the current implementation we would get a reference to the original source and maybe change it after calling render causing a side effect on the original source which could cause some unexpected behaviors if one assume render would always return a new string...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about return @template.dup if @template.empty?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just think '' makes it obvious we are returning an empty string...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe that test could be adapted for taking the empty string into account, since the encoding shouldn't matter for empty strings...

data_context = Native.make_data_context(@template)
context = Native.data_context_get_context(data_context)
native_options = Native.context_get_options(context)
Expand Down
5 changes: 5 additions & 0 deletions test/engine_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,10 @@ def test_inline_source_maps
assert_match /sourceMappingURL/, output
assert_match /.foo/, output
end

def test_empty_template
output = Engine.new('').render
assert_equal '', output
end
end
end