Skip to content

Commit

Permalink
fix(ux): 🐛 fix non-reversible \ escaping (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNZL committed Jun 24, 2023
1 parent 74f58a2 commit 3f5a679
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
7 changes: 4 additions & 3 deletions src/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ public static string ExtractFromQuery(Query query, int index)
: string.Join(" ", query.SearchTerms.Skip(index));
}

public static string ReplaceSearchBackslashes(string search)
public static string UnescapeSearch(string search)
{
return Regex.Replace(search, @"(\\(?!\\))", string.Empty);
}

public static string EscapePotentialFlags(string description)
public static string EscapeDescription(string description)
{
return Regex.Replace(description, @" -", @" \-");
string escaped = Regex.Replace(description, @"(\\(?!\\))", @"\\");
return Regex.Replace(escaped, @" -", @" \-");
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions src/Structures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public TimeEntry(DetailedReportTimeEntryResponse timeEntryResponse, DetailedRepo
}

string rawDescription = (escapePotentialFlags)
? Main.EscapePotentialFlags(this._rawDescription)
? Main.EscapeDescription(this._rawDescription)
: this._rawDescription;

if (!withTrailingSpace)
Expand All @@ -218,7 +218,7 @@ public string GetDescription(bool escapePotentialFlags = false)
}

return (escapePotentialFlags)
? Main.EscapePotentialFlags(this._rawDescription)
? Main.EscapeDescription(this._rawDescription)
: this._rawDescription;
}

Expand Down Expand Up @@ -546,7 +546,7 @@ object ICloneable.Clone()
}

string rawTitle = (escapePotentialFlags)
? Main.EscapePotentialFlags(this._rawTitle)
? Main.EscapeDescription(this._rawTitle)
: this._rawTitle;

if (!withTrailingSpace)
Expand All @@ -565,7 +565,7 @@ public string GetTitle(bool escapePotentialFlags = false)
}

return (escapePotentialFlags)
? Main.EscapePotentialFlags(this._rawTitle)
? Main.EscapeDescription(this._rawTitle)
: this._rawTitle;
}

Expand Down
8 changes: 4 additions & 4 deletions src/TogglTrack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ internal async ValueTask<List<Result>> RequestStartEntry(CancellationToken token
long workspaceId = project?.WorkspaceId ?? me.DefaultWorkspaceId;

string projectName = project?.WithClientName ?? "No Project";
string description = Main.ReplaceSearchBackslashes(Main.ExtractFromQuery(query, ArgumentIndices.Description));
string description = Main.UnescapeSearch(Main.ExtractFromQuery(query, ArgumentIndices.Description));

var results = new List<Result>();

Expand Down Expand Up @@ -795,7 +795,7 @@ internal async ValueTask<List<Result>> RequestStartEntry(CancellationToken token
var startTime = DateTimeOffset.UtcNow + startTimeSpan;

// Remove -t flag from description
string sanitisedDescription = Main.ReplaceSearchBackslashes(
string sanitisedDescription = Main.UnescapeSearch(
string.Join(" ", query.SearchTerms.Take(Array.IndexOf(query.SearchTerms, Settings.TimeSpanFlag)).Skip(ArgumentIndices.Description))
);

Expand Down Expand Up @@ -1415,7 +1415,7 @@ internal async ValueTask<List<Result>> RequestEditEntry(CancellationToken token,
var project = me.GetProject(this._state.SelectedIds.Project);

string projectName = project?.WithClientName ?? "No Project";
string description = Main.ReplaceSearchBackslashes(Main.ExtractFromQuery(
string description = Main.UnescapeSearch(Main.ExtractFromQuery(
query,
(this._state.EditProject == TogglTrack.EditProjectState.ProjectSelected)
? ArgumentIndices.DescriptionWithProject
Expand Down Expand Up @@ -1667,7 +1667,7 @@ internal async ValueTask<List<Result>> RequestEditEntry(CancellationToken token,
}

// Remove flags from description
string sanitisedDescription = Main.ReplaceSearchBackslashes(
string sanitisedDescription = Main.UnescapeSearch(
string.Join(
" ",
query.SearchTerms
Expand Down

0 comments on commit 3f5a679

Please sign in to comment.