joplin / joplin/plugin-templates

wrapInQuotes skips values containing a double quote, so helper arguments break frontmatter parsing

Open Beginner friendly
#177 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
207
Forks
40
Avg merge
7d 16h
Merged PRs (30d)
2

Description

`preProcessTemplateBody` wraps the value of the special variables (`template_title`, `template_tags`, `template_notebook`, `template_todo_alarm`) in double quotes so the frontmatter parses, but `wrapInQuotes` skips any value that already contains a double quote:

```ts
// Don't do anything if it already contains a double quote
if (firstMatch.indexOf("\"") !== -1) {
continue;
}
```

The intent is presumably "the user already quoted this, leave it alone". But it also skips values where the quotes are *inside* a helper argument, which is exactly the case that needs the outer quotes.

The template from #156:

```yaml
---
template_title: {{datetime format = "dddd D [de] MMMM de YYYY"}}
---
```

The value contains `"`, so the auto-quoting bails, the frontmatter is left unquoted, and YAML fails on the leading `{`. The user sees "There was an error parsing this template".

Verified against that exact template: the pattern matches the line, and the double quote check then skips it.

The workaround, which a commenter on #156 found, is to wrap the value in single quotes by hand. That works, but the whole point of `wrapInQuotes` is that users should not have to.

A better test than "contains a double quote" would be whether the value *starts* with a quote, since that is what actually indicates the user quoted it themselves.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at the preProcessTemplateBody and wrapInQuotes functions described in the issue, then reproduce the supplied YAML template with the datetime helper argument. The fix is done when values containing internal double quotes are wrapped so frontmatter parses, while values already beginning with a quote remain unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.