Obsidian crashes in very specific circumstances due to LF vs CRLF

Summary

Creating a new note with very specific frontmatter information crashes obsidian in Windows 10 and 11 after LF is replaced with CRLF.
The very specific frontmatter information I’m talking about is code originally meant for templater, but the issue persists even after uninstalling the plugin.

Steps to reproduce

  1. Create a new note.
  2. In the note’s frontmatter, put 2 lines with templater ternary operators back to back (templater doesn’t need to be installed for this to work). The note should look like this:
---
<% 'foo' === 'bar' ? 'true: ' : 'false: ' %>
<% 'bar' === 'bar' ? 'true: ' : 'false: ' %>
---
Content...
  1. (optional) Close the note.
  2. Replace LF with CRLF anyway you want and save the file (originally, this happened because I backup my vault with git. However, the issue persisted if I changed LF → CRLF locally)

Did you follow the troubleshooting guide?

Yes

Expected result

If you followed step 3 and closed the note:
When re-opening the note, Obsidian should convert CRLF → LF like it usually does, and nothing should break.

If you didn’t follow step 3 and didn’t close the note:
Obsidian should be able to handle CRLF and nothing should break.

Actual result

If you followed step 3 and closed the note:
When re-opening the note, Obsidian instantly freezes, and no action is doable. If you ever try to open the note, Obsidian goes into this frozen state. If the developer console was open before, it’s still responsive, if not, you can’t open it.

(If you had the note in your workspace, for example, if you closed obsidian → converted LF → CRLF, and reopened it. Obsidian will not start, simply get stuck in ‘Loading Workspace’.)

If you didn’t follow step 3 and didn’t close the note:
Obsidian instantly freezes. No action is doable.

Environment

SYSTEM INFO:
Obsidian version: v1.6.5
Installer version: v1.5.12
Operating system: Windows 10 Pro 10.0.19045
Login status: logged in
Catalyst license: none
Insider build toggle: off
Live preview: on
Base theme: dark
Community theme: none
Snippets enabled: 0
Restricted mode: on

Also happens on my windows 11 laptop.


Additional information

It used to work before 2024-07-12. How I discovered this was:

  • I had Templater, Calendar, Periodic Notes, and Homepage (along with other plugins that didn’t impact) installed
  • Homepage was set to daily note
  • I used git to backup my vault.
  • At 00:04 of 2024-07-12, when opening Obsidian to log my thoughts at night, it wouldn’t open. Simply freeze.
  • Deleted Homepage from the plugin folder, and Obsidian opened.
  • When I tried to open the note of 2024-07-12, obsidian would crash. (it was created before, right before obsidian crashed by Homepage i think.) So I deleted it aswell and tried to create it.
  • Creating a future note when clicking on the calendar crashed Obsidian. (removed calendar)
  • Creating today’s note if it hadn’t already been created using Periodic Notes crashed Obsidian. (removed periodic notes)
  • Tried with core plugin Daily Notes: same issue

(At this point I thought the problem was templater)

  • Tried adding the daily template to a random file using the Templater Modal - it worked, which got me confused. (But knowing now I guess templater processes the notes first when appending a template. However, when triggered by new file creation that has a predefined template from another plugin, the problem exists before templater can do anything about it.)
  • Reinstalled all plugins.
  • Tried creating daily notes in various ways with different template - worked.

At this point I realized templater wasn’t the problem, but probably the template was.

  • opening the template crashed obsidian.

For clarity, my daily template looks like this:

---
tags:
  - journal
  - daily
  - <% tp.user.getWeekDayName(tp.file.title).toLowerCase() %>
Week: "[[<% tp.user.getWeekFromDay(tp.file.title) %>]]"
day-of-week: <% tp.user.getWeekDayName(tp.file.title).toLowerCase() %>
wake-up: 
bed-time: 
<% tp.user.getWeekDayName(tp.file.title) === 'Sunday' ? 'weight: ' : '' %>
<% tp.user.getWeekDayName(tp.file.title) === 'Sunday' ? 'weight-reflection: ' : ''
summary: 
---
Other stuff aswell that didnt impact

After a lot of experimenting, I isolated the problem to these 2 lines:

<% tp.user.getWeekDayName(tp.file.title) === 'Sunday' ? 'weight: ' : '' %>
<% tp.user.getWeekDayName(tp.file.title) === 'Sunday' ? 'weight-reflection: ' : ''

and replacing them with:

<%*
 if (tp.user.getWeekDayName(tp.file.title) === 'Sunday') {
     tR += `weight: 
weight-reflection: `
%>

fixed the issue, even when keeping CRLF line endings. I don’t know the underlying motive that causes the crash, just that it does for some reason.

When trying to isolate the issue, creating a new test file with just those 2 lines worked locally, so again I was confused.

So when I went to my other PC to try to replicate the issue, suddenly the daily template worked fine and the test note I had created crashed obsidian. So I reflected on what the f*** was different between my laptop and workstation, and I realised the only thing different were the line endings.

But it’s so weird that it works literally everywhere else. I even tried to replicate it with different stuff in those 2 lines. After converting to CRLF: (worked means did NOT crash)
2x <% %> worked
2x <% ? : %> worked
2x <% '' === '' ? '' : '' %> worked
2x <% false === '' ? 'a: ' : 'b: ' %> worked
2x <% 'foo' === 'foo' ? 'a: ' : 'b: ' %> crashed
2x <% false === 'foo: ' ? 'a: ' : 'b: ' %> crashed
2x <% true ? 'ok: ' : '' %> worked
2x <% false === 'true' ? '' : '' %> crashed

So many things worked, and my edge case completely breaks obsidian. Weird bug honestly.

Can you attach here or link me a copy of file that causes obsidian to crash?

I went ahead and created a barebones vault where I reproduced the issue.

It’s on github here: