#13435 Improve string list parsing for backslashes and quotes

Enhanced parsing in PdmFieldScriptingCapabilityIOHandler to correctly handle backslashes and escape sequences in both quoted and unquoted strings. Unquoted Windows paths now preserve backslashes, while quoted strings process escape sequences as expected. Added unit tests to verify correct handling of both cases.

Add tests for Windows-style path handling in rips API

Introduce test_windows_paths.py with two pytest tests to verify correct handling of Windows-style file paths (backslashes) in the rips Python API.
This commit is contained in:
Magne Sjaastad committed 2026-02-02 16:35:53 +01:00
1 parent d47de408aa
commit 5356f078a5
3 files changed
+116 -7

No files matched your search

@@ -68,22 +68,36 @@ void PdmFieldScriptingCapabilityIOHandler<QString>::writeToField( QString&
while ( !inputStream.atEnd() )
{
currentChar = errorMessageContainer->readCharWithLineNumberCount( inputStream );
if ( !currentChar.isNull() && currentChar != QChar( '\\' ) )
if ( currentChar.isNull() )
{
if ( currentChar == QChar( '"' ) ) // End Quote
// Null character - add as is
accumulatedFieldValue += currentChar;
}
else if ( currentChar == QChar( '"' ) )
{
// End Quote - reached end of string
validStringEnd = true;
break;
}
else if ( currentChar == QChar( '\\' ) && stringsAreQuoted )
{
// Process escape sequence only when strings are quoted
// Read the next character after the backslash
if ( !inputStream.atEnd() )
{
// Reached end of string
validStringEnd = true;
break;
currentChar = errorMessageContainer->readCharWithLineNumberCount( inputStream );
accumulatedFieldValue += currentChar;
}
else
{
accumulatedFieldValue += currentChar;
// Backslash at end of input - add it as is
accumulatedFieldValue += QChar( '\\' );
}
}
else
{
currentChar = errorMessageContainer->readCharWithLineNumberCount( inputStream );
// Regular character (including backslashes when strings are not quoted)
accumulatedFieldValue += currentChar;
}
}
@@ -97,6 +97,54 @@ TEST( PdmFieldSerialization, StringListQuoted )
EXPECT_STREQ( "B-4H", destination[1].toStdString().c_str() );
}
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
TEST( PdmFieldSerialization, StringListWithBackslashes )
{
// Test that Windows paths with backslashes are properly preserved when stringsAreQuoted = false
// This is the typical case when paths are sent from Python via gRPC
QString source = R"([C:\Users\file.txt, D:\Data\project.txt])";
QTextStream stream( &source );
std::vector<QString> destination;
caf::PdmScriptIOMessages messages;
bool stringsAreQuoted = false; // Strings in lists from Python are not quoted
caf::PdmFieldScriptingCapabilityIOHandler<std::vector<QString>>::writeToField( destination,
stream,
&messages,
stringsAreQuoted );
EXPECT_EQ( (size_t)2, destination.size() );
EXPECT_STREQ( "C:\\Users\\file.txt", destination[0].toStdString().c_str() );
EXPECT_STREQ( "D:\\Data\\project.txt", destination[1].toStdString().c_str() );
}
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
TEST( PdmFieldSerialization, StringListQuotedWithEscapedBackslashes )
{
// When strings ARE quoted (e.g., from command files), backslashes should be escaped
// and the escape sequences should be processed
QString source = R"(["C:\\Users\\file.txt", "D:\\Data\\project.txt"])";
QTextStream stream( &source );
std::vector<QString> destination;
caf::PdmScriptIOMessages messages;
bool stringsAreQuoted = true;
caf::PdmFieldScriptingCapabilityIOHandler<std::vector<QString>>::writeToField( destination,
stream,
&messages,
stringsAreQuoted );
EXPECT_EQ( (size_t)2, destination.size() );
EXPECT_STREQ( "C:\\Users\\file.txt", destination[0].toStdString().c_str() );
EXPECT_STREQ( "D:\\Data\\project.txt", destination[1].toStdString().c_str() );
}
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
TEST( PdmFieldSerialization, ValueList )