Menu

#2228 Custom functions unquote strings

open
nobody
2018-01-30
2018-01-23
Anonymous
No

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"; }

Discussion

  • Anonymous

    Anonymous - 2018-01-30

    Originally posted by: saper

    Correct, we currently convert sass strings into JavaScript strings and we have no room to store the 'quoted' flag anywhere...

     
  • Anonymous

    Anonymous - 2018-01-30

    Originally posted by: nex3

    @saper According to my experiments with Node Sass 4.7.2, the String objects are instances of SassString, not JavaScript's String type.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.