Skip to content

Commit

Permalink
Release v8.3.1: Fix crash with empty Rpath query
Browse files Browse the repository at this point in the history
FIX: previously a RemesPath query that was empty or only whitespace
	could cause Notepad++ to crash.
	Now this error is caught and properly handled.
FIX: Properly throw an error with (hopefully) all cases where
	two valid RemesPath queries are not separated by a binop.
	For example, `@[0] * 7 3` or `7 + 9 s_len(bar)`
	would previously not have thrown errors even though they are syntactic nonsense.
  • Loading branch information
molsonkiko committed Dec 23, 2024
1 parent 39dc41a commit 4d85e55
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 60 deletions.
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Change Log
All [notable changes](#830---2024-12-22) to this project will be documented in this file.
All [notable changes](#831---2024-12-22) to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
Expand Down Expand Up @@ -48,9 +48,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Since v7.0, holding down `Enter` in a multiline textbox (like the [tree viewer query box](/docs/README.md#remespath)) only adds one newline when the key is lifted.
- Maybe use pre-7.1 (dictionary-based rather than indicator-based) [selection remembering](/docs/README.md#working-with-selections) for Notepad++ 8.5.5 and earlier? Indicators are risky with those older NPP's because of the lack of `NPPM_ALLOCATEINDICATOR`.

## [8.3.0] - 2024-12-22
## [8.3.1] - 2024-12-22

### Added
### Fixed

1. Fixed bug where running a [RemesPath query in the tree view](/docs/README.md#remespath) would cause a crash if the query box was empty or contained only whitespace.
2. Fixed bug where some errors would not be raised on some syntactically invalid RemesPath queries containing two valid items not separated by a binary operator. For example, `1 * -2 7` and `bar + @[0] 9` both had this problem.

## [8.3.0] - 2024-12-22

### Changed

Expand Down
4 changes: 3 additions & 1 deletion JsonToolsNppPlugin/JSONTools/RemesPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2019,6 +2019,8 @@ private Obj_Pos ParseExprFunc(List<object> toks, int pos, int end, JQueryContext
pos = opo.pos;
if (!(opo.obj is JNode onode))
throw new RemesPathException($"Expected JNode, got {opo.obj.GetType()}");
if (leftOperand is JNode leftNode)
throw new RemesPathException($"Two JNodes {leftNode.ToString()} and {onode.ToString()} with no binop in between");
nt = PeekNextToken(toks, pos - 1, end);
if (nt == null || (nt is char nd_ && EXPR_FUNC_ENDERS.Contains(nd_)))
{
Expand All @@ -2040,7 +2042,7 @@ private Obj_Pos ParseExprFunc(List<object> toks, int pos, int end, JQueryContext
}
if (leftOperand == null)
{
throw new RemesPathException("Null return from ParseExprOrScalar");
throw new RemesPathException("Null return from ParseExprFunc");
}
return new Obj_Pos(leftOperand, pos);
}
Expand Down
2 changes: 2 additions & 0 deletions JsonToolsNppPlugin/JSONTools/RemesPathLexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public override string ToString()
/// </summary>
public static string MarkLocationOfSyntaxError(string query, int lexpos, string msg)
{
if (query.Length == 0)
return "Error: query is empty or contains only whitespace";
if (lexpos < 0)
lexpos = 0;
else if (lexpos >= query.Length)
Expand Down
4 changes: 2 additions & 2 deletions JsonToolsNppPlugin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("8.3.0.0")]
[assembly: AssemblyFileVersion("8.3.0.0")]
[assembly: AssemblyVersion("8.3.1.0")]
[assembly: AssemblyFileVersion("8.3.1.0")]
Binary file modified JsonToolsNppPlugin/Release_x64.zip
Binary file not shown.
Binary file modified JsonToolsNppPlugin/Release_x86.zip
Binary file not shown.
9 changes: 9 additions & 0 deletions JsonToolsNppPlugin/Tests/RemesPathTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,15 @@ public static bool Test()
List<string[]> testcases = new List<string[]>
{
new [] {"", "[0]"}, // empty query
new [] {"3 3", "[0]"}, // two JNodes not separated by binop
new [] {"1 * -2 7", "[\"foo\"]"}, // JNode after binop not separated by binop from another JNode.
new [] {"@ * 4 foo = 17", "[\"foo\"]"}, // JNode after binop not separated by binop from another JNode (in a mutator expression before the `=`)
new [] {"@ * 4 = foo * 7 blah", "[\"foo\"]"}, // JNode after binop not separated by binop from another JNode (in a mutator expression after the `=`)
new [] {"3 * 3 s_slice(@[0], -1)", "[\"foo\"]"}, // JNode after binop not separated by binop from another JNode (function of input).
new [] {"bar + @[0] 9", "[\"foo\"]"}, // JNode (function of input) after binop not separated by binop from another JNode.
new [] {"bar + at(@, 0) enumerate(@)", "[\"foo\"]"}, // JNode (function of input) after binop not separated by binop from another JNode (function of input).
new [] {"@{@ + foo 7}", "[\"foo\"]"}, // inside a projection, JNode after binop not separated by binop from another JNode
new [] {"@[1] 3 * 3", "[1, \"a\"]"}, // JNode not separated by binop from another JNode (which is followed by binop)
new [] {" \t \r\n", "[0]"}, // query with only whitespace
new [] {"concat(j`[1, 2]`, j`{\"a\": 2}`)", "[]"}, // concat throws with mixed arrays and objects
new [] {"concat(@, 1)", "[1, 2]"}, // concat throws with non-iterables
Expand Down
Loading

0 comments on commit 4d85e55

Please sign in to comment.