Templater icon indicating copy to clipboard operation
Templater copied to clipboard

templater script fails if comment contains apostrophe

Open Smitty010 opened this issue 2 years ago • 2 comments

I'm using the latest obsidian and templater plugin (v0.15.9/1.12.0). I saw this bug which seemed really odd to me. inside the templater script, I had a comment which contained the word "doesn't".

Here's how I just replicated the problem. I added this to a template.

<%*
// doesn't work
%>

I get the log message

plugin:templater-obsidian:82 Templater Error: Template parsing error, aborting. 
 unclosed string at line 62 col 9:

  // doesn't work
          ^

Removing the comment makes the problem go away. Is this expected behavior? Is there some preprocessing on the script that doesn't ignore comments when doing an initial scan?

Smitty010 avatar Aug 22 '22 16:08 Smitty010

I think your guess is correct.

AB1908 avatar Aug 22 '22 16:08 AB1908

What happens if you escape the apostrophe: doesn't

I don't think there is any special handling of comments when processing a command.

shabegom avatar Sep 06 '22 12:09 shabegom

Hey @Smitty010 I think this was fixed in 1.6.0, could you update and confirm?

SilentVoid13 avatar Nov 09 '22 20:11 SilentVoid13

I assume you mean templater 1.16.0.

I think it may be fixed.  I modified a templater file I had to add a comment that had an apostrophe.  I got a syntax error.  I then updated.  I still got a syntax error.  However, I realized that I screwed up adding the comment in in such a way that there really was a syntax error (my bad).  I fixed that and it seemed to work even with the apostrophe.  Here's the snippet (note the apostrophe in the comment).

if (!tp.file.exists(yearLink)) { // if the yearlink doesn't exist
    await app.vault.createFolder(dir)
}

I don't have a great way to roll back to 1.15.0 to determine if it would have failed then.  So, I think it is fixed now.  But, I had eliminated all comments with apostrophes so that templater would work a while ago. I just can't be sure that this example would have failed before.

I'm willing to assume it if fixed and then I'll reopen it if I see it again.  Since it only affects comments, it's not a show stopper.

FYI - templater is very central to what I do and multiple templates get run each day.  It's a great tool.

Scott

P.S. I just tried the example I put in the original post. It also works fine. So, I'm comfortable that it is likely fixed and closing it is OK.

Smitty010 avatar Nov 09 '22 21:11 Smitty010