diff --git a/gh-md-toc b/gh-md-toc index 8d35839..a23d2f7 100755 --- a/gh-md-toc +++ b/gh-md-toc @@ -69,7 +69,7 @@ gh_toc_md2html() { local gh_tmp_file_md=$gh_file_md if [ "$skip_header" = "yes" ]; then - if grep -Fxq "" $gh_src; then + if grep -Fxq "" "$gh_src"; then # cut everything before the toc gh_tmp_file_md=$gh_file_md~~ sed '1,//d' $gh_file_md > $gh_tmp_file_md @@ -168,7 +168,7 @@ gh_toc(){ local toc=`echo "$rawhtml" | gh_toc_grab "$gh_src_copy" "$indent"` echo "$toc" if [ "$need_replace" = "yes" ]; then - if grep -Fxq "" $gh_src && grep -Fxq "" $gh_src; then + if grep -Fxq "" "$gh_src" && grep -Fxq "" "$gh_src"; then echo "Found markers" else echo "You don't have or in your file...exiting" @@ -198,7 +198,7 @@ gh_toc(){ fi echo if [ "${no_backup}" = "yes" ]; then - rm ${toc_path} ${gh_src}${ext} + rm "$toc_path" "$gh_src$ext" fi echo "!! TOC was added into: '$gh_src'" if [ -z "${no_backup}" ]; then diff --git a/tests/test directory/test_filepathwithspace.md b/tests/test directory/test_filepathwithspace.md new file mode 100644 index 0000000..aea1249 --- /dev/null +++ b/tests/test directory/test_filepathwithspace.md @@ -0,0 +1,17 @@ +# Title + + + +- [Title](#title) + - [This is test for file path with space](#this-is-test-for-file-path-with-space) + + + + + + +Blabla... + +## This is test for file path with space + +Blabla... diff --git a/tests/tests.bats b/tests/tests.bats index 5431db5..ee525b9 100755 --- a/tests/tests.bats +++ b/tests/tests.bats @@ -201,3 +201,11 @@ test_help() { assert_equal "${lines[2]}" "* [C vs C++](#c-vs-c)" } + +@test "Toc for file path with space, #136" { + run $BATS_TEST_DIRNAME/../gh-md-toc --insert tests/test\ directory/test_filepathwithspace.md + assert_success + + assert_equal "${lines[2]}" "* [Title](#title)" + assert_equal "${lines[3]}" " * [This is test for file path with space](#this-is-test-for-file-path-with-space)" +} \ No newline at end of file