Custom functions unquote strings
:rainbow: Node.js bindings to libsass
Brought to you by:
imran1012000k
Originally created by: nex3
If a user passes a quoted string into Node Sass's custom functions, it will unquote that string. This means it's impossible to write Node Sass functions that preserve existing values as-is, even if the functions don't inspect or modify those values at all.
For example:
var sass = require('node-sass'); const { StringDecoder } = require('string_decoder'); var result = sass.renderSync({ data: 'a {b: id("foo")}', functions: { 'id($arg)': function(arg) { return arg; } } }); var dec = new StringDecoder('utf8'); console.log(dec.write(result.css));
This prints:
a { b: foo; }
but it should print:
a { b: "foo"; }
Originally posted by: saper
Correct, we currently convert sass strings into JavaScript strings and we have no room to store the 'quoted' flag anywhere...
Originally posted by: nex3
@saper According to my experiments with Node Sass 4.7.2, the String objects are instances of
SassString
, not JavaScript'sString
type.