Skip to content

Commit b496091

Browse files
committed
#171: Unicode fixes to the rest of the regex patterns.
1 parent ffcedc0 commit b496091

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

src/Common.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export function combineObjects(...objects: Object[]) {
103103
export function normalizePath2(path: string) {
104104
// 1. Preparations
105105
path = path.trim();
106-
const leading_slashes_regexp = /^[/\\]*/g; // Get as many / or \ slashes as there are in the very beginning of path. Can also be "" (an empty string).
106+
const leading_slashes_regexp = /^[/\\]*/gu; // Get as many / or \ slashes as there are in the very beginning of path. Can also be "" (an empty string).
107107
let leading_slashes = leading_slashes_regexp.exec(path)[0];
108108

109109
// 2. Run the original normalizePath()
@@ -114,8 +114,8 @@ export function normalizePath2(path: string) {
114114
if (isWindows()) {
115115
// The platform is Windows.
116116
// Convert / to \
117-
path = path.replace(/\//g, "\\"); // Need to use a regexp instead of a normal "/" -> "\\" replace because the normal replace would only replace first occurrence of /.
118-
leading_slashes = leading_slashes.replace(/\//g, "\\"); // Same here.
117+
path = path.replace(/\//gu, "\\"); // Need to use a regexp instead of a normal "/" -> "\\" replace because the normal replace would only replace first occurrence of /.
118+
leading_slashes = leading_slashes.replace(/\//gu, "\\"); // Same here.
119119
}
120120
// Now ensure that path still contains leading slashes (if there were any before calling normalizePath()).
121121
// Check that the path should have a similar set of leading slashes at the beginning. It can be at least "/" (on linux/Mac), or "\\" (on Windows when it's a network path), in theory even "///" or "\\\\\" whatever.
@@ -173,9 +173,9 @@ export function generateObsidianCommandName(plugin: SC_Plugin, shell_command: st
173173

174174
export function isInteger(value: string, allow_minus: boolean): boolean {
175175
if (allow_minus) {
176-
return !!value.match(/^-?\d+$/);
176+
return !!value.match(/^-?\d+$/u);
177177
} else {
178-
return !!value.match(/^\d+$/);
178+
return !!value.match(/^\d+$/u);
179179
}
180180
}
181181

src/output_channels/OutputChannelDriver_OpenFiles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class OutputChannelDriver_OpenFiles extends OutputChannelDriver {
3434
// Future compatibility: Ensure there is no newline characters in-between the output.
3535
// This is to reserve newline usage to future when this output channel will support opening multiple files at once.
3636
// TODO: Remove this check when multi-file support is implemented.
37-
if (file_definition.match(/[\r\n]/)) {
37+
if (file_definition.match(/[\r\n]/u)) {
3838
// Bad, the output contains a newline.
3939
this.plugin.newErrors([
4040
"Cannot open file: The output contains linebreaks: " + file_definition,

src/output_channels/OutputChannelDriver_StatusBar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class OutputChannelDriver_StatusBar extends OutputChannelDriver {
1919
status_bar_element.setAttr("aria-label", stdout_and_stderr);
2020

2121
// Show last line permanently.
22-
const output_message_lines = stdout_and_stderr.split(/(\r\n|\r|\n)/);
22+
const output_message_lines = stdout_and_stderr.split(/(\r\n|\r|\n)/u);
2323
const last_output_line = output_message_lines[output_message_lines.length - 1];
2424
status_bar_element.setText(last_output_line);
2525
}

src/settings/setting_elements/Autocomplete.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function createAutocomplete(input_element: HTMLInputElement, autocomplete
4545
if ("}}" === after_caret) {
4646
// The replacing will happen in a {{variable}}.
4747
// Do not accidentally insert another }} pair.
48-
supplement = supplement.replace(/}}$/, ""); // Only removes a trailing }} if there is one.
48+
supplement = supplement.replace(/\}\}$/u, ""); // Only removes a trailing }} if there is one.
4949
}
5050

5151
// Try to save part of the beginning, in case it seems like not being part of the search query.
@@ -72,7 +72,7 @@ export function createAutocomplete(input_element: HTMLInputElement, autocomplete
7272

7373
// Move the caret to a logical continuation point
7474
caret_position = replace_start + supplement.length;
75-
if (supplement.match(/:}}$/)) {
75+
if (supplement.match(/:\}\}$/u)) {
7676
// Place the caret after the colon, instead of after }}.
7777
caret_position -= 2;
7878
}
@@ -193,7 +193,7 @@ export function addCustomAutocompleteItems(custom_autocomplete_yaml: string) {
193193
if (type === "normal-variable") {
194194
// Add an unescaped version of the variable, too
195195
CustomAutocompleteItems.push({
196-
value: autocomplete_item_value.replace(/^{{/, "{{!"), // Add an exclamation mark to the variable name.
196+
value: autocomplete_item_value.replace(/^\{\{/u, "{{!"), // Add an exclamation mark to the variable name.
197197
help_text: autocomplete_item_label,
198198
group: group_name,
199199
type: "unescaped-variable",
@@ -245,18 +245,18 @@ interface IAutocompleteSearchQuery {
245245
* @param typed_text
246246
*/
247247
function get_search_query(typed_text: string): IAutocompleteSearchQuery {
248-
let search_text = typed_text.match(/\S*?$/)[0]; // Reduce the text - limit to a single word (= exclude spaces and everything before them).
248+
let search_text = typed_text.match(/\S*?$/u)[0]; // Reduce the text - limit to a single word (= exclude spaces and everything before them).
249249
let search_type: AutocompleteSearchQueryType = "other"; // May be overwritten.
250250

251251
if (search_text.contains("}}")) {
252252
// The query happens right after a {{variable}}.
253253
// Make the query string to start after the }} pair, i.e. remove }} and everything before it. This improves the search.
254-
search_text = search_text.replace(/.+}}/, "");
254+
search_text = search_text.replace(/.+\}\}/u, "");
255255
}
256256
if (search_text.contains("{{")) {
257257
// A {{variable}} is being queried.
258258
// Make the query string to start from the {{ pair, i.e. remove everything before {{ . This improves the search.
259-
search_text = search_text.replace(/.+{{/, "{{");
259+
search_text = search_text.replace(/.+\{\{/u, "{{");
260260
if (search_text.contains("{{!")) {
261261
// An _unescaped_ variable is searched for.
262262
search_type = "unescaped-variable";

src/variables/VariableHelpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,15 @@ export function getFileYAMLValue(app: App, file: TFile, property_path: string) {
116116
let property_name: string = property_parts.shift();
117117

118118
// Check if the property name is a negative numeric index.
119-
if (property_name.match(/^-\d+$/)) {
119+
if (property_name.match(/^-\d+$/u)) {
120120
// The property name is a negative number.
121121
// Check that yaml_object contains at least one element.
122122
const yaml_object_keys = Object.getOwnPropertyNames(yaml_object).filter(key => key !== "length"); // All _really custom_ yaml keys, not .length
123123
if (yaml_object_keys.length > 0) {
124124
// Check if yaml_object happens to be an indexed list.
125125
let is_indexed_list = true;
126126
yaml_object_keys.forEach((key) => {
127-
if (!key.match(/^\d+$/)) {
127+
if (!key.match(/^\d+$/u)) {
128128
// At least one non-numeric key was found, so consider the object not to be an indexed list.
129129
is_indexed_list = false;
130130
}

0 commit comments

Comments
 (0)