Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Conditionally strip-out markdown in note previews
Tests have been failing because `noteTitleAndPreview` is reported to be taking longer than 1ms to run. In fact, `Date.now()`, which we were using to validate this, includes reduced time precision for protection against timing attacks. In this patch I've done two things to address the failing tests: - Replace `Date.now()` with `process.hrtime()` which gives us nanosecond precision - Run the function-under-test 100 times in order to eliminate variance in the measurement While fixing this test I noted a flaw in `noteTitleAndPreview` that we missed in #1647. We created the helper function `removeMarkdownFromOutput` which transforms a string based on whether or not markdown is enabled for the note. Unfortunately for us we were setting a module-global function based on the module-init-time value `isMarkdown`, which as a function is always truthy, meaning that it would return a function that alwasy removed markdown regardless of the note. In this patch I've addressed this by passing `stripMarkdown` into that function. In the PR for #1647 we discussed this parameter and removed it but we kept `removeMarkdownFromOutput` outside the scope of `noteTitleAndPreview`. We could leave out the parameter and move the function into `noteTitleAndPreview` or we could add the parameter back. For the purpose of only creating that function once I have added the parameter back in. `noteTitleAndPreview` gets called in some inner loops and I preferred to avoid recreating the filtering function on every call, or at least until the JIT figured it out; I'm sure that the performance impact is insignificant but I don't see any benefit to one way over the other and I'd rather do less work as the default.
- Loading branch information