From fd2595f961d081f3bce598292be406411363ba0c Mon Sep 17 00:00:00 2001 From: Murray Stevenson <50844517+murraystevenson@users.noreply.github.com> Date: Mon, 29 Jul 2024 14:09:06 -0700 Subject: [PATCH 1/2] SetAlgo : Treat set expressions containing only whitespace as empty --- Changes.md | 3 +++ python/GafferSceneTest/SetAlgoTest.py | 10 ++++++++++ src/GafferScene/SetAlgo.cpp | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Changes.md b/Changes.md index ed1e4e2d256..2ad8143077f 100644 --- a/Changes.md +++ b/Changes.md @@ -1,7 +1,10 @@ 1.4.x.x (relative to 1.4.10.0) ======= +Improvements +------------ +- SetExpressions : Set Expressions containing only whitespace characters are now treated as empty rather than producing an error. 1.4.10.0 (relative to 1.4.9.0) ======== diff --git a/python/GafferSceneTest/SetAlgoTest.py b/python/GafferSceneTest/SetAlgoTest.py index 91ebec9e90e..7775645708d 100644 --- a/python/GafferSceneTest/SetAlgoTest.py +++ b/python/GafferSceneTest/SetAlgoTest.py @@ -134,6 +134,16 @@ def test( self ) : expressionCheck( '(setA - ((setC /group/group/sphere2) & setB))', [ '/group/group/sphere1' ] ) expressionCheck( 'setA - (/group/group/sphere1 /group/group/sphere2) | (setA setB setC) & setC', [ '/group/sphere3' ] ) + # Test expressions containing only whitespace are treated as empty + expressionCheck( '', [] ) + expressionCheck( ' ', [] ) + expressionCheck( '\n', [] ) + expressionCheck( ' \n ', [] ) + expressionCheck( '\t', [] ) + expressionCheck( ' \t ', [] ) + expressionCheck( '\n \t', [] ) + expressionCheck( '\t\n\t \n \t\n', [] ) + # Test if proper exception is thrown for invalid expression with self.assertRaises( RuntimeError ) as e : # note the missing ) diff --git a/src/GafferScene/SetAlgo.cpp b/src/GafferScene/SetAlgo.cpp index 511b19def20..a2b16beaca6 100644 --- a/src/GafferScene/SetAlgo.cpp +++ b/src/GafferScene/SetAlgo.cpp @@ -439,7 +439,7 @@ struct ExpressionGrammar : qi::grammar Date: Tue, 30 Jul 2024 15:15:43 -0700 Subject: [PATCH 2/2] SetAlgo : Add tests for set expressions containing tabs and newlines --- python/GafferSceneTest/SetAlgoTest.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/python/GafferSceneTest/SetAlgoTest.py b/python/GafferSceneTest/SetAlgoTest.py index 7775645708d..8b5ecc6dc1f 100644 --- a/python/GafferSceneTest/SetAlgoTest.py +++ b/python/GafferSceneTest/SetAlgoTest.py @@ -134,6 +134,16 @@ def test( self ) : expressionCheck( '(setA - ((setC /group/group/sphere2) & setB))', [ '/group/group/sphere1' ] ) expressionCheck( 'setA - (/group/group/sphere1 /group/group/sphere2) | (setA setB setC) & setC', [ '/group/sphere3' ] ) + # Test a selection of the above expressions with tab and newline whitespace characters inserted + expressionCheck( 'setA\nsetC', [ '/group/group/sphere1', '/group/group/sphere2', '/group/sphere3' ] ) + expressionCheck( '\n\nsetA\tsetC\n\n\t', [ '/group/group/sphere1', '/group/group/sphere2', '/group/sphere3' ] ) + expressionCheck( 'setA\t-\tsetB\n|\nsetC', [ '/group/group/sphere1', '/group/sphere3' ] ) + expressionCheck( 'setA\n| setB\n& setC', [ '/group/group/sphere1', '/group/group/sphere2' ] ) + expressionCheck( '/group/light1\n/group/light2', [ '/group/light1', '/group/light2' ] ) + expressionCheck( '/group/light1\t/group/light2\n', [ '/group/light1', '/group/light2' ] ) + expressionCheck( '(\n\t/group/light1\n\t/group/light2\n)\n|\nsetA', [ '/group/light1', '/group/light2', '/group/group/sphere1', '/group/group/sphere2' ] ) + expressionCheck( '(\nsetA - \n(\n\t(\n\t\tsetC /group/group/sphere2\n\t)\n & setB)\n)\n', [ '/group/group/sphere1' ] ) + # Test expressions containing only whitespace are treated as empty expressionCheck( '', [] ) expressionCheck( ' ', [] )