Skip to content

Commit

Permalink
fix: Handle any hidden VS16 character on all emojis
Browse files Browse the repository at this point in the history
This fixes #3179
  • Loading branch information
claremacrae committed Nov 21, 2024
1 parent 7ed67f7 commit 27ad4f4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/TaskSerializer/DefaultTaskSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ function dateFieldRegex(symbols: string) {
}

function fieldRegex(symbols: string, valueRegexString: string) {
let source = symbols;
// \uFE0F? allows an optional Variant Selector 16 on emojis.
let source = symbols + '\uFE0F?';
if (valueRegexString !== '') {
source += ' *' + valueRegexString;
}
Expand Down Expand Up @@ -95,8 +96,7 @@ export const DEFAULT_SYMBOLS: DefaultTaskSerializerSymbols = {
TaskFormatRegularExpressions: {
// The following regex's end with `$` because they will be matched and
// removed from the end until none are left.
// \uFE0F? allows an optional Variant Selector 16 on emojis.
priorityRegex: fieldRegex('([πŸ”Ίβ«πŸ”ΌπŸ”½β¬])\uFE0F?', ''),
priorityRegex: fieldRegex('([πŸ”Ίβ«πŸ”ΌπŸ”½β¬])', ''),
startDateRegex: dateFieldRegex('πŸ›«'),
createdDateRegex: dateFieldRegex('βž•'),
scheduledDateRegex: dateFieldRegex('[β³βŒ›]'),
Expand All @@ -105,7 +105,7 @@ export const DEFAULT_SYMBOLS: DefaultTaskSerializerSymbols = {
cancelledDateRegex: dateFieldRegex('❌'),
recurrenceRegex: fieldRegex('πŸ”', '([a-zA-Z0-9, !]+)'),
onCompletionRegex: fieldRegex('🏁', '([a-zA-Z]+)'),
dependsOnRegex: fieldRegex('β›”\uFE0F?', '(' + taskIdSequenceRegex.source + ')'),
dependsOnRegex: fieldRegex('β›”', '(' + taskIdSequenceRegex.source + ')'),
idRegex: fieldRegex('πŸ†”', '(' + taskIdRegex.source + ')'),
},
} as const;
Expand Down
20 changes: 10 additions & 10 deletions tests/TaskSerializer/DefaultTaskSerializer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ describe('validate emoji regular expressions', () => {
expect(generateRegexApprovalTest()).toMatchInlineSnapshot(`
"
priorityRegex: /([πŸ”Ίβ«πŸ”ΌπŸ”½β¬])\\ufe0f?$/u
startDateRegex: /πŸ›« *(\\d{4}-\\d{2}-\\d{2})$/u
createdDateRegex: /βž• *(\\d{4}-\\d{2}-\\d{2})$/u
scheduledDateRegex: /[β³βŒ›] *(\\d{4}-\\d{2}-\\d{2})$/u
dueDateRegex: /[πŸ“…πŸ“†πŸ—“] *(\\d{4}-\\d{2}-\\d{2})$/u
doneDateRegex: /βœ… *(\\d{4}-\\d{2}-\\d{2})$/u
cancelledDateRegex: /❌ *(\\d{4}-\\d{2}-\\d{2})$/u
recurrenceRegex: /πŸ” *([a-zA-Z0-9, !]+)$/u
onCompletionRegex: /🏁 *([a-zA-Z]+)$/u
startDateRegex: /πŸ›«\\ufe0f? *(\\d{4}-\\d{2}-\\d{2})$/u
createdDateRegex: /βž•\\ufe0f? *(\\d{4}-\\d{2}-\\d{2})$/u
scheduledDateRegex: /[β³βŒ›]\\ufe0f? *(\\d{4}-\\d{2}-\\d{2})$/u
dueDateRegex: /[πŸ“…πŸ“†πŸ—“]\\ufe0f? *(\\d{4}-\\d{2}-\\d{2})$/u
doneDateRegex: /βœ…\\ufe0f? *(\\d{4}-\\d{2}-\\d{2})$/u
cancelledDateRegex: /❌\\ufe0f? *(\\d{4}-\\d{2}-\\d{2})$/u
recurrenceRegex: /πŸ”\\ufe0f? *([a-zA-Z0-9, !]+)$/u
onCompletionRegex: /🏁\\ufe0f? *([a-zA-Z]+)$/u
dependsOnRegex: /β›”\\ufe0f? *([a-zA-Z0-9-_]+( *, *[a-zA-Z0-9-_]+ *)*)$/u
idRegex: /πŸ†” *([a-zA-Z0-9-_]+)$/u
idRegex: /πŸ†”\\ufe0f? *([a-zA-Z0-9-_]+)$/u
"
`);
});
Expand Down Expand Up @@ -122,7 +122,7 @@ describe.each(symbolMap)("DefaultTaskSerializer with '$taskFormat' symbols", ({
expect(taskDetails).toMatchTaskDetails({ ['scheduledDate']: moment('2021-06-20', 'YYYY-MM-DD') });
});

it.failing('should parse a scheduledDate - with Variation Selector', () => {
it('should parse a scheduledDate - with Variation Selector', () => {
// This test showed the existence of https://github.com/obsidian-tasks-group/obsidian-tasks/issues/3179
const input = '⏳️ 2024-11-18';
expect(hasVariantSelector16(input)).toBe(true);
Expand Down

0 comments on commit 27ad4f4

Please sign in to comment.