CMakePP / CMakePPLang

Object-oriented extension to the CMake language.
http://cmakepp.github.io/CMakePPLang/
Apache License 2.0
11 stars 4 forks source link

cpp_serialize doesn't work correctly with nested lists #15

Closed blakemulnix closed 4 years ago

blakemulnix commented 4 years ago

Describe the bug cpp_serialize doesn't work correctly with nested lists because it is currently a macro and the way arguments are passed into macros in CMake causes weird things to happen with escape characters.

Example of the problem Here is an example showing the problem:

# Create nested list that in readable form looks like:
# [ "1", "11", [ "2", "22", [ "3", "33", "333" ], "222", "2222" ], "111", "1111" ]
# Note, this list behaves as expected when iterating over it recursively
set(deep_list 1;11;2\\\;22\\\;3\\\\\;33\\\\\;333\\\;222\\\;2222;111;1111)

# Serialize list and print out result
cpp_serialize(serialized_list "${deep_list}")
message("${serialized_list}")

# Outputs:
# [ "1", "11", [ "2", "22", "3", "33", "333", "222", "2222" ], "111", "1111" ]

Expected behavior I'd expect the list to be serialized correctly.

Additional context Changing the cpp_serialize macro to be a function fixes this issue. We should probably check that no other weird things are happening due to this macro escape character issue. Here is an example of the issue on its own:

macro(test_macro param1 param2)
    message("${param1}")
    message("${param2}")
endmacro()

function(test_func param1 param2)
    message("${param1}")
    message("${param2}")
endfunction()

test_macro(
    "This should be two backslashes: \\\\"
    "This should be a backslash and a quote: \\\" "
)
test_func(
    "This should be two backslashes: \\\\ "
    "This should be a backslash and a quote: \\\" "
)

Outputs:

This should be two backslashes: \
This should be a backslash and a quote: " 
This should be two backslashes: \\ 
This should be a backslash and a quote: \" 
ryanmrichard commented 4 years ago

Fixed with #16