JuliaDocs / LiveServer.jl

Simple development server with live-reload capability for Julia.
MIT License
143 stars 26 forks source link

Windows + Literate => Regex crash due to abspath escaped characters #181

Open behinger opened 4 months ago

behinger commented 4 months ago

I get an error on the regexp ERROR: PCRE compilation error: \ at end of pattern for the literate part when running LiveServer.jl from several windows systems.

The reasons seems to lay in: https://github.com/tlienart/LiveServer.jl/blob/eec3d5b23d16e296ba55c4f99084c1814bee5165/src/utils.jl#L249 which translates something like literate="Foo" to c:\\Foo\\. Unfortunately, this is not a correct regular expression, and thus later at https://github.com/tlienart/LiveServer.jl/blob/eec3d5b23d16e296ba55c4f99084c1814bee5165/src/utils.jl#L165

the Regex(literate) throws the error (at what letter exactly is a bit surprisingly different on different windows machines / paths we tested... but haven't systematically tested it either).

I'm not entirely sure how to fix it, because I dont fully understand the function in L165. Maybe one can escape the sequence better?

PS: You can try that Regex("c:\\Foo\\") throws an error, or on windows machine Regex(abspath(".")) - note that sometimes it only complains about the last "\", but if you are unlikely and hit some special escaped things like "\F", it fails earlier ;)

tlienart commented 2 days ago

Hello, sorry for the delay in responding and thanks for the details

the stuff around L165:

I think the best path here would be to change

path = replace(spath[1], Regex("^$literate") => joinpath(foldername, "src")) 

with

path = joinpath(foldername, "src", chopprefix(spath[1], literate))

(I wasn't aware of chopprefix at the time of writing those lines)

julia> chopprefix("c:\\Foo\\Bar\\baz", "c:\\Foo\\")
"Bar\\baz"

would you be interested in trying this and opening a PR? thanks!

also cc @fredrikekre since it touches upon Literate and he's much more responsive than I 🙏