Fix: Conditionally strip-out markdown in note previews #1839
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Tests have been failing because
noteTitleAndPreview
is reported to be takinglonger than 1ms to run. In fact,
Date.now()
, which we were using to validatethis, includes reduced time precision for protection against timing attacks. In
this patch I've done two things to address the failing tests:
Date.now()
withprocess.hrtime()
which gives us nanosecondprecision
measurement
While fixing this test I noted a flaw in
noteTitleAndPreview
that we missedin #1647. We created the helper function
removeMarkdownFromOutput
whichtransforms 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 thatfunction. In the PR for #1647 we discussed this parameter and removed it but we
kept
removeMarkdownFromOutput
outside the scope ofnoteTitleAndPreview
. Wecould 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 preferredto 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.
Sorry @belcherj for not catching this in the original PR
Testing
The test-fix will run itself in CircleCI. You can validate the note list behavior for
notes with and without markdown formatting enabled.
In the following screenshots the notes have the following content:
and
Before
After