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

Cannot interpolate columns with "." in name #303

Closed
karlcz opened this issue Dec 15, 2016 · 4 comments
Closed

Cannot interpolate columns with "." in name #303

karlcz opened this issue Dec 15, 2016 · 4 comments
Assignees
Labels

Comments

@karlcz
Copy link
Contributor

karlcz commented Dec 15, 2016

I need to be able to interpolate all columns even if they have names that mustache does not like, e.g. with a . character (or any other that mustache might disallow).

  • ideally, we should use a template system that does not make assumptions about names
  • alternatively, we might use a workaround like string-replacing or otherwise "escaping" unsafe characters while producing the markdown environment, so someone writing an annotation can use this mangled name to access the column data
@karlcz karlcz added the bug label Dec 15, 2016
@chiragsanghvi
Copy link
Contributor

chiragsanghvi commented Dec 15, 2016

I think we might need to get rid of Mustache as escaping also won't work. In addition other template languages also won't support it as . in javascript is a property of an object. janl/mustache.js#343

We can use handlebars, but for it you need to explicitly enclose the column-name in quotes if it has a dot or any special character that conflicts with handlebars syntax.

// Change this object to change your values
var obj = {
   ID: "Alice's Adventures in Wonderland \t what is this",
   "this.is": "some name"
};

var handlebars = require("handlebars");
console.log(handlebars.compile('{{ID}} - {{"this.is"}}')(obj));

We can switch back to the old string replacement. Which I am sure supports it, but it won't have the encode and other escaping stuff.

https://runkit.com/chiragsanghvi/57b4b5f94c7bbd13004b43f6

@hongsudt
Copy link
Contributor

hongsudt commented Dec 15, 2016 via email

@hongsudt
Copy link
Contributor

@karlcz can you please describe the workaround here..

@karlcz
Copy link
Contributor Author

karlcz commented Dec 16, 2016

@hongsudt it's the second option I described in the original issue. Mangle column names when producing the environment object passed to the mustache interpreter, i.e. replace . or any other disallowed character with _ when forming the object keys for the environment dictionary.

Then, the DBA can mangle the names the same way in order to be able to use guards or interpolation based on that column.

Don't worry about collisions. If a DBA uses column names that differ only in . versus _, they can suffer the consequences...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants