From 0eaed09517efd9731cc81a90e9e7fb6440d1e974 Mon Sep 17 00:00:00 2001 From: Ali Chraghi Date: Sun, 27 Mar 2022 14:16:38 +0430 Subject: [PATCH] TextEditor: Update file argument parser regex pattern --- Userland/Applications/TextEditor/FileArgument.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Userland/Applications/TextEditor/FileArgument.cpp b/Userland/Applications/TextEditor/FileArgument.cpp index e6acff471e..128103d22e 100644 --- a/Userland/Applications/TextEditor/FileArgument.cpp +++ b/Userland/Applications/TextEditor/FileArgument.cpp @@ -17,15 +17,14 @@ FileArgument::FileArgument(String file_argument) m_column = {}; // A file doesn't exist with the full specified name, maybe the user entered line/column coordinates? - Regex re("^(.+?)(:([0-9]+):?([0-9]+)?)?$"); + Regex re("^(.+?)(?::([0-9]+))?(?::([0-9]+))?$"); RegexResult result = match(file_argument, re, PosixFlags::Global | PosixFlags::Multiline | PosixFlags::Ungreedy); auto& groups = result.capture_group_matches.at(0); // Match 0 group 0: file name // Match 0 group 1: line number // Match 0 group 2: column number - - if (groups.size() > 3) { + if (groups.size() > 2) { // Both a line and column number were specified. auto filename = groups.at(0).view.to_string(); auto initial_line_number = groups.at(1).view.to_string().to_int(); @@ -36,7 +35,7 @@ FileArgument::FileArgument(String file_argument) m_line = initial_line_number.value(); if (initial_column_number.has_value()) m_column = initial_column_number.value(); - } else if (groups.size() == 3) { + } else if (groups.size() == 2) { // Only a line number was specified. auto filename = groups.at(0).view.to_string(); auto initial_line_number = groups.at(1).view.to_string().to_int();