Please include the explanation in a comment. It is easy to not understand the context...

- henrik

9 jul 2013 kl. 18:58 skrev Thomas Hallgren <notifications@github.com>:

> In lib/puppet/pops/binder/hiera2/string_evaluator.rb:
> 
> > +      val = @scope[key]
> > +      return val unless val.nil?
> > +      @diag.accept(Issues::UNRESOLVED_STRING_VARIABLE, x, { :key => key })
> > +      val = ''
> > +    end
> > +
> > +    def _eval_TextExpression(o, x)
> > +      _eval(o.expr, x)
> > +    end
> > +
> > +    def _eval_ConcatenatedString(o, x)
> > +      o.segments.collect { |s| _eval(s, x) }.join()
> > +    end
> > +
> > +    def self.quote(x)
> > +      escaped = x.gsub(/\\|"/) { |c| "\\#{c}" }
> The intention is to quote an arbitrary string so that it becomes the exact same arbitrary string when parsed (forget about interpolation for a moment). This, in my mind, yields the following rules:
> 
> If the string contains a NL (binary 0xa) then I assume that the quote method should translated that into the two character backslash-n. The same is true for other control characters 0x8 (tab), 0xd (CR). All with the intention that the string will again contain control characters again once it has been parsed. I assume that both the YAML and the JSON parser will see to that strings containing backslash-n will appear as 0xa when they are sent to the quote method.
> If the string contains backslash, then that backslash has to be escaped. If it isn't, then control sequences entered as two character controls (like backslash-n) will change by the quote/parse and instead become a binary 0xa. Again, the quote/parse operation must leave the string unchanged. Please note that a string that contains a backslash when passed to the quote method has been entered as two backslashes by the user and then transformed by the YAML or JSON parser.
> If the string contains a double quote, then that must be prefixed with a backslash in order to become a quote again when parsed.
> IMO, the current regexp lacks the transformation of the control characters into their corresponding backslash construct but it is correct otherwise.
> 
> —
> Reply to this email directly or view it on GitHub.