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

fix: Enable reading of high priority emoji with Variant Selector 16 appended #2695

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/TaskSerializer/DefaultTaskSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ 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.
priorityRegex: /([🔺⏫🔼🔽⏬])$/u,
// \uFE0F? allows an optional Variant Selector 16 on emojis.
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,
Expand Down
28 changes: 28 additions & 0 deletions tests/TaskSerializer/DefaultTaskSerializer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ type DefaultTaskSerializeSymbolMap = readonly {
// A map that facilitates parameterizing the tests over symbols
const symbolMap: DefaultTaskSerializeSymbolMap = [{ taskFormat: 'tasksPluginEmoji', symbols: DEFAULT_SYMBOLS }];

/**
* Since Variant Selectors are invisible, any tests whose behaviour is dependent on the
* presence or absence of one MUST 'expect' on the result of this function,
* to confirm that the test is doing what it claims to be doing.
* @param text
*/
function hasVariantSelector16(text: string) {
const vs16Regex = /\uFE0F/u;
return text.match(vs16Regex) !== null;
}

// NEW_TASK_FIELD_EDIT_REQUIRED

describe.each(symbolMap)("DefaultTaskSerializer with '$taskFormat' symbols", ({ symbols }) => {
Expand Down Expand Up @@ -67,6 +78,23 @@ describe.each(symbolMap)("DefaultTaskSerializer with '$taskFormat' symbols", ({
expect(taskDetails).toMatchTaskDetails({ priority });
}
});

it('should parse a high priority without Variant Selector 16', () => {
const line = '⏫';
expect(hasVariantSelector16(line)).toBe(false);

const taskDetails = deserialize(line);
expect(taskDetails).toMatchTaskDetails({ priority: Priority.High });
});

it('should parse a high priority with Variant Selector 16', () => {
// This test showed the existing of https://github.com/obsidian-tasks-group/obsidian-tasks/issues/2273
const line = '⏫️'; // There is a hidden Variant Selector 16 character at the end of this string
expect(hasVariantSelector16(line)).toBe(true);

const taskDetails = deserialize(line);
expect(taskDetails).toMatchTaskDetails({ priority: Priority.High });
});
});

it('should parse a recurrence', () => {
Expand Down