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

Invalid characters for $FOAM_TITLE used in .foam_template.filepath fails silently #1216

Open
redactedscribe opened this issue Apr 25, 2023 · 2 comments

Comments

@redactedscribe
Copy link

redactedscribe commented Apr 25, 2023

Describe the bug

See title.

Small Reproducible Example

No response

Steps to Reproduce the Bug or Issue

  1. Use $FOAM_TITLE as part of .foam_template.filepath's value.
  2. Create note from template.
  3. Title using invalid NTFS file system characters: Invalid "Characters"
  4. File creation fails without any feedback as to why or what happened.

Expected behavior

Automatically strip invalid characters from the title and use that as the valid file name (as already happens when $FOAM_TITLE is outside of .foam_template.filepath). Of course, mentions of $FOAM_TITLE elsewhere should retain all the submitted characters.

Screenshots or Videos

No response

Operating System Version

Windows 11

Visual Studio Code Version

VSCodium 1.77.3

Additional context

This can be worked around by using filepath: "${FOAM_TITLE/[\/?*\"<>|:\\]/_/g}.md" to replace each of Windows' invalid characters with an underscore. This only works around the failure to create the file, however, if you now provide a title with or without an invalid character, another related bug is encountered at this point (duplication of text), see #1215.

Foam should probably handle these invalid characters instead of the user having to use VS Code variable transforms such as above.

@redactedscribe
Copy link
Author

redactedscribe commented Apr 25, 2023

If you work around the failing file creation using the variable transform provided above, here is some of the duplication (as described in #1215) which can occur. I think the positions of the $-references worsen the problem. A simplified example:

This template...

---
foam_template:
  filepath: "$FOAM_DATE_YEAR-$FOAM_DATE_MONTH-$FOAM_DATE_DATE $FOAM_TITLE.md"
title: $1
---

# $FOAM_DATE_YEAR-$FOAM_DATE_MONTH-$FOAM_DATE_DATE ${1:$FOAM_TITLE}

Some text.

$1

...with title "My daily note" becomes the note:

---
title: My daily note daily note
---

# 2023-04-25 ${1:My daily note2023-04-25 ${1:-04-25 My daily note daily note

Some text.

My daily note daily note

As you can see, duplication happens even without invalid characters.

@riccardoferretti
Copy link
Collaborator

partially fixed in #1232

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

No branches or pull requests

2 participants