Skip to content

Commit ee4be4a

Browse files
committed
Fix end of string issue with quotes.
1 parent 5e73745 commit ee4be4a

4 files changed

Lines changed: 40 additions & 5 deletions

File tree

src/client/fix_imports.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ void fix_imports(const String &target, const path &aliases_file, const path &old
5656
auto aliases_s = read_file(aliases_file);
5757
auto dep = extractFromString(target);
5858

59-
fs::create_directories(new_file.parent_path());
59+
if (!new_file.parent_path().empty())
60+
fs::create_directories(new_file.parent_path());
6061
std::ofstream ofile(new_file.string());
6162
if (!ofile)
6263
throw std::runtime_error("Cannot open the output file for writing");

src/support/cppan_string.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ int get_end_of_string_block(const String &s, int i)
2929

3030
if (c == '\"')
3131
{
32-
if (n_quotes == 0)
33-
i = get_end_of_string_block(s.c_str(), i + 1) - 1;
34-
else if (s[i - 1] == '\\')
32+
if (i && s[i - 1] == '\\')
3533
;
34+
else if (n_quotes == 0)
35+
i = get_end_of_string_block(s, i + 1) - 1;
3636
else
3737
n_quotes--;
3838
}
@@ -42,7 +42,7 @@ int get_end_of_string_block(const String &s, int i)
4242
{
4343
case '(':
4444
case '[':
45-
i = get_end_of_string_block(s.c_str(), i + 1) - 1;
45+
i = get_end_of_string_block(s, i + 1) - 1;
4646
break;
4747
case ')':
4848
n_curly--;

test/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ set_property(TARGET source_test PROPERTY FOLDER test)
1313
target_link_libraries(source_test common pvt.cppan.demo.philsquared.catch)
1414
add_test(NAME source COMMAND source_test)
1515

16+
add_executable(string_test string.cpp)
17+
set_property(TARGET string_test PROPERTY FOLDER test)
18+
target_link_libraries(string_test support pvt.cppan.demo.philsquared.catch)
19+
add_test(NAME string COMMAND string_test)
20+
1621
################################################################################

test/string.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
name: main
3+
4+
*/
5+
6+
#include <cppan_string.h>
7+
8+
#define CATCH_CONFIG_RUNNER
9+
#include <catch.hpp>
10+
11+
TEST_CASE("save/load", "[source]")
12+
{
13+
std::string s(R"xxx((pvt.cppan.demo.xz_utils.lzma-5.2.3 PROPERTIES
14+
INTERFACE_COMPILE_DEFINITIONS "CPPAN_API_pvt_cppan_demo_xz_utils_lzma_5_2_3=CPPAN_SYMBOL_IMPORT;CPPAN;CPPAN_BUILD;CPPAN_SYMBOL_EXPORT=__attribute__((__visibility__(\"default\")));CPPAN_SYMBOL_IMPORT=;HAVE_CLOCK_GETTIME=1;HAVE_FUTIMENS=1;HAVE_FUTIMES=1;HAVE_FUTIMESAT=1;HAVE_POSIX_FADVISE=1;HAVE_UTIME=1;HAVE_UTIMES=1;HAVE_FCNTL_H=1;HAVE_IMMINTRIN_H=1;HAVE_INTTYPES_H=1;HAVE_LIMITS_H=1;HAVE_MEMORY_H=1;HAVE_STDBOOL_H=1;HAVE_STDDEF_H=1;HAVE_STDINT_H=1;HAVE_STDLIB_H=1;HAVE_STRINGS_H=1;HAVE_STRING_H=1;HAVE_SYS_STAT_H=1;HAVE_SYS_TIME_H=1;HAVE_SYS_TYPES_H=1;HAVE_UNISTD_H=1;HAVE_INT32_T=1;SIZEOF_INT32_T=4;SIZE_OF_INT32_T=4;HAVE_INT64_T=1;SIZEOF_INT64_T=8;SIZE_OF_INT64_T=8;HAVE_SIZE_T=1;SIZEOF_SIZE_T=8;SIZE_OF_SIZE_T=8;HAVE_UINT16_T=1;SIZEOF_UINT16_T=2;SIZE_OF_UINT16_T=2;HAVE_UINT32_T=1;SIZEOF_UINT32_T=4;SIZE_OF_UINT32_T=4;HAVE_UINT64_T=1;SIZEOF_UINT64_T=8;SIZE_OF_UINT64_T=8;HAVE_UINT8_T=1;SIZEOF_UINT8_T=1;SIZE_OF_UINT8_T=1;HAVE_UINTPTR_T=1;SIZEOF_UINTPTR_T=8;SIZE_OF_UINTPTR_T=8;HAVE_VOID_P=1;SIZEOF_VOID_P=8;SIZE_OF_VOID_P=8;HAVE__BOOL=1;SIZEOF__BOOL=1;SIZE_OF__BOOL=1;STDC_HEADERS=1;HAVE_DECL_CLOCK_MONOTONIC=0;HAVE_DECL__MM_MOVEMASK_EPI8=0;HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC=1"
15+
INTERFACE_INCLUDE_DIRECTORIES "/tmp/1/s/obj/a7/68/fa0b/build/f30476c3/cppan/a768fa0b;/tmp/1/s/src/a7/68/fa0b/src/liblzma/api;/tmp/1/s/src/a7/68/fa0b"
16+
INTERFACE_LINK_LIBRARIES "m;pthread;rt;dl"
17+
)gdfgfdg
18+
dfgdf
19+
)xxx");
20+
21+
auto e = get_end_of_string_block(s, 1);
22+
REQUIRE(e == 1445);
23+
}
24+
25+
int main(int argc, char **argv)
26+
{
27+
auto rc = Catch::Session().run(argc, argv);
28+
return rc;
29+
}

0 commit comments

Comments
 (0)