l3build icon indicating copy to clipboard operation
l3build copied to clipboard

file-functions: escapepath weirdness

Open jlaurens opened this issue 4 years ago • 4 comments

A cross platform problem this escape function reads

function escapepath(path)
  if os_type == "windows" then
    local path,count = gsub(path,'"','')
    if count % 2 ~= 0 then
      print("Unbalanced quotes in path")
      exit(0)
    else
      if match(path," ") then
        return '"' .. path .. '"'
      end
      return path
    end
  else
    path = gsub(path,"\\ ","[PATH-SPACE]")
    path = gsub(path," ","\\ ")
    return gsub(path,"%[PATH-SPACE%]","\\ ")
  end
end

On windows, paths can contain an even number of '"' characters whereas on unix it can contain any number of such delimiter. This seems weird because escapepath is used to escape the paths defined in build.lua which should be platform agnostic.

jlaurens avatar Feb 08 '21 13:02 jlaurens

The defaults are, but we have to watch for users ;)

josephwright avatar Feb 08 '21 13:02 josephwright

I don't really understand what is exactly behind the scene. If this is some kind of error recovery, then it should be done on the unix side too, otherwise the same build.lua may break on the unix side.

jlaurens avatar Feb 08 '21 16:02 jlaurens

I don't really understand what is exactly behind the scene. If this is some kind of error recovery, then it should be done on the unix side too, otherwise the same build.lua may break on the unix side.

The point is we can get

some-variable = "../An Awkard Dir"

in the build.lua file, which shows up after we've set the defaults. Now, there are some places I've not got things right with spaces, but this covers a reasonable number of them.

josephwright avatar Feb 08 '21 17:02 josephwright

Ah, I see. What puzzled me is that your tests are covering something very different like

some_variable = "../An\" Awkard \"Dir"
other_variable = 'foo"bar"baz'

It does not seem so awkward to deliberately exclude some "exotic" file names, but some kind of note would help. Maybe raising an error would be appropriate.

jlaurens avatar Feb 10 '21 14:02 jlaurens

Looking back, the point is that this is the same as the rule we using in expl3: *nix might allow " chars, but Windows really doesn't, so we don't. I think the logic is correct as-is.

josephwright avatar Jul 16 '23 19:07 josephwright