diff options
-rwxr-xr-x | Master/bin/win32/luatools.lua | 54 | ||||
-rwxr-xr-x | Master/bin/win32/mtxrun.lua | 54 | ||||
-rwxr-xr-x | Master/texmf-dist/scripts/context/lua/luatools.lua | 54 | ||||
-rwxr-xr-x | Master/texmf-dist/scripts/context/lua/mtxrun.lua | 54 | ||||
-rwxr-xr-x | Master/texmf-dist/scripts/context/stubs/mswin/luatools.lua | 54 | ||||
-rwxr-xr-x | Master/texmf-dist/scripts/context/stubs/mswin/mtxrun.lua | 54 | ||||
-rwxr-xr-x | Master/texmf-dist/scripts/context/stubs/unix/luatools | 54 | ||||
-rwxr-xr-x | Master/texmf-dist/scripts/context/stubs/unix/mtxrun | 54 | ||||
-rw-r--r-- | Master/texmf-dist/tex/context/base/l-file.lua | 54 |
9 files changed, 378 insertions, 108 deletions
diff --git a/Master/bin/win32/luatools.lua b/Master/bin/win32/luatools.lua index 581ba70c86a..ac1e38f4c6d 100755 --- a/Master/bin/win32/luatools.lua +++ b/Master/bin/win32/luatools.lua @@ -2214,22 +2214,52 @@ end -- we can hash them weakly + +local insert = table.insert + function file.collapse_path(str) + if str == "" or str =="." then + return "." + elseif find(str,"^%.%.") then + return str + elseif not find(str,"%.") then + return str + end + str = gsub(str,"^%./",lfs.currentdir() .. "/") -- ./xx in qualified str = gsub(str,"\\","/") - if find(str,"/") then - str = gsub(str,"^%./",(gsub(lfs.currentdir(),"\\","/")) .. "/") -- ./xx in qualified - str = gsub(str,"/%./","/") - local n, m = 1, 1 - while n > 0 or m > 0 do - str, n = gsub(str,"[^/%.]+/%.%.$","") - str, m = gsub(str,"[^/%.]+/%.%./","") + local oldelements = checkedsplit(str,"/") + local newelements = { } + local i = #oldelements + while i > 0 do + local element = oldelements[i] + if element == '.' then + -- do nothing + elseif element == '..' then + local n = i -1 + while n > 0 do + local element = oldelements[n] + if element ~= '..' and element ~= '.' then + oldelements[n] = '.' + break + else + n = n - 1 + end + end + if n<1 then + insert(newelements,1,'..') + end + elseif element ~= "" then + insert(newelements,1,element) end - str = gsub(str,"([^/])/$","%1") - -- str = gsub(str,"^%./","") -- ./xx in qualified - str = gsub(str,"/%.$","") + i = i - 1 + end + if #newelements == 0 then + return "." + elseif find(str,"^/") then + return "/" .. concat(newelements,'/') + else + return concat(newelements, '/') end - if str == "" then str = "." end - return str end --~ print(file.collapse_path("/a")) diff --git a/Master/bin/win32/mtxrun.lua b/Master/bin/win32/mtxrun.lua index d6b2d13a71a..574335c58d5 100755 --- a/Master/bin/win32/mtxrun.lua +++ b/Master/bin/win32/mtxrun.lua @@ -2223,22 +2223,52 @@ end -- we can hash them weakly + +local insert = table.insert + function file.collapse_path(str) + if str == "" or str =="." then + return "." + elseif find(str,"^%.%.") then + return str + elseif not find(str,"%.") then + return str + end + str = gsub(str,"^%./",lfs.currentdir() .. "/") -- ./xx in qualified str = gsub(str,"\\","/") - if find(str,"/") then - str = gsub(str,"^%./",(gsub(lfs.currentdir(),"\\","/")) .. "/") -- ./xx in qualified - str = gsub(str,"/%./","/") - local n, m = 1, 1 - while n > 0 or m > 0 do - str, n = gsub(str,"[^/%.]+/%.%.$","") - str, m = gsub(str,"[^/%.]+/%.%./","") + local oldelements = checkedsplit(str,"/") + local newelements = { } + local i = #oldelements + while i > 0 do + local element = oldelements[i] + if element == '.' then + -- do nothing + elseif element == '..' then + local n = i -1 + while n > 0 do + local element = oldelements[n] + if element ~= '..' and element ~= '.' then + oldelements[n] = '.' + break + else + n = n - 1 + end + end + if n<1 then + insert(newelements,1,'..') + end + elseif element ~= "" then + insert(newelements,1,element) end - str = gsub(str,"([^/])/$","%1") - -- str = gsub(str,"^%./","") -- ./xx in qualified - str = gsub(str,"/%.$","") + i = i - 1 + end + if #newelements == 0 then + return "." + elseif find(str,"^/") then + return "/" .. concat(newelements,'/') + else + return concat(newelements, '/') end - if str == "" then str = "." end - return str end --~ print(file.collapse_path("/a")) diff --git a/Master/texmf-dist/scripts/context/lua/luatools.lua b/Master/texmf-dist/scripts/context/lua/luatools.lua index 581ba70c86a..ac1e38f4c6d 100755 --- a/Master/texmf-dist/scripts/context/lua/luatools.lua +++ b/Master/texmf-dist/scripts/context/lua/luatools.lua @@ -2214,22 +2214,52 @@ end -- we can hash them weakly + +local insert = table.insert + function file.collapse_path(str) + if str == "" or str =="." then + return "." + elseif find(str,"^%.%.") then + return str + elseif not find(str,"%.") then + return str + end + str = gsub(str,"^%./",lfs.currentdir() .. "/") -- ./xx in qualified str = gsub(str,"\\","/") - if find(str,"/") then - str = gsub(str,"^%./",(gsub(lfs.currentdir(),"\\","/")) .. "/") -- ./xx in qualified - str = gsub(str,"/%./","/") - local n, m = 1, 1 - while n > 0 or m > 0 do - str, n = gsub(str,"[^/%.]+/%.%.$","") - str, m = gsub(str,"[^/%.]+/%.%./","") + local oldelements = checkedsplit(str,"/") + local newelements = { } + local i = #oldelements + while i > 0 do + local element = oldelements[i] + if element == '.' then + -- do nothing + elseif element == '..' then + local n = i -1 + while n > 0 do + local element = oldelements[n] + if element ~= '..' and element ~= '.' then + oldelements[n] = '.' + break + else + n = n - 1 + end + end + if n<1 then + insert(newelements,1,'..') + end + elseif element ~= "" then + insert(newelements,1,element) end - str = gsub(str,"([^/])/$","%1") - -- str = gsub(str,"^%./","") -- ./xx in qualified - str = gsub(str,"/%.$","") + i = i - 1 + end + if #newelements == 0 then + return "." + elseif find(str,"^/") then + return "/" .. concat(newelements,'/') + else + return concat(newelements, '/') end - if str == "" then str = "." end - return str end --~ print(file.collapse_path("/a")) diff --git a/Master/texmf-dist/scripts/context/lua/mtxrun.lua b/Master/texmf-dist/scripts/context/lua/mtxrun.lua index d6b2d13a71a..574335c58d5 100755 --- a/Master/texmf-dist/scripts/context/lua/mtxrun.lua +++ b/Master/texmf-dist/scripts/context/lua/mtxrun.lua @@ -2223,22 +2223,52 @@ end -- we can hash them weakly + +local insert = table.insert + function file.collapse_path(str) + if str == "" or str =="." then + return "." + elseif find(str,"^%.%.") then + return str + elseif not find(str,"%.") then + return str + end + str = gsub(str,"^%./",lfs.currentdir() .. "/") -- ./xx in qualified str = gsub(str,"\\","/") - if find(str,"/") then - str = gsub(str,"^%./",(gsub(lfs.currentdir(),"\\","/")) .. "/") -- ./xx in qualified - str = gsub(str,"/%./","/") - local n, m = 1, 1 - while n > 0 or m > 0 do - str, n = gsub(str,"[^/%.]+/%.%.$","") - str, m = gsub(str,"[^/%.]+/%.%./","") + local oldelements = checkedsplit(str,"/") + local newelements = { } + local i = #oldelements + while i > 0 do + local element = oldelements[i] + if element == '.' then + -- do nothing + elseif element == '..' then + local n = i -1 + while n > 0 do + local element = oldelements[n] + if element ~= '..' and element ~= '.' then + oldelements[n] = '.' + break + else + n = n - 1 + end + end + if n<1 then + insert(newelements,1,'..') + end + elseif element ~= "" then + insert(newelements,1,element) end - str = gsub(str,"([^/])/$","%1") - -- str = gsub(str,"^%./","") -- ./xx in qualified - str = gsub(str,"/%.$","") + i = i - 1 + end + if #newelements == 0 then + return "." + elseif find(str,"^/") then + return "/" .. concat(newelements,'/') + else + return concat(newelements, '/') end - if str == "" then str = "." end - return str end --~ print(file.collapse_path("/a")) diff --git a/Master/texmf-dist/scripts/context/stubs/mswin/luatools.lua b/Master/texmf-dist/scripts/context/stubs/mswin/luatools.lua index 581ba70c86a..ac1e38f4c6d 100755 --- a/Master/texmf-dist/scripts/context/stubs/mswin/luatools.lua +++ b/Master/texmf-dist/scripts/context/stubs/mswin/luatools.lua @@ -2214,22 +2214,52 @@ end -- we can hash them weakly + +local insert = table.insert + function file.collapse_path(str) + if str == "" or str =="." then + return "." + elseif find(str,"^%.%.") then + return str + elseif not find(str,"%.") then + return str + end + str = gsub(str,"^%./",lfs.currentdir() .. "/") -- ./xx in qualified str = gsub(str,"\\","/") - if find(str,"/") then - str = gsub(str,"^%./",(gsub(lfs.currentdir(),"\\","/")) .. "/") -- ./xx in qualified - str = gsub(str,"/%./","/") - local n, m = 1, 1 - while n > 0 or m > 0 do - str, n = gsub(str,"[^/%.]+/%.%.$","") - str, m = gsub(str,"[^/%.]+/%.%./","") + local oldelements = checkedsplit(str,"/") + local newelements = { } + local i = #oldelements + while i > 0 do + local element = oldelements[i] + if element == '.' then + -- do nothing + elseif element == '..' then + local n = i -1 + while n > 0 do + local element = oldelements[n] + if element ~= '..' and element ~= '.' then + oldelements[n] = '.' + break + else + n = n - 1 + end + end + if n<1 then + insert(newelements,1,'..') + end + elseif element ~= "" then + insert(newelements,1,element) end - str = gsub(str,"([^/])/$","%1") - -- str = gsub(str,"^%./","") -- ./xx in qualified - str = gsub(str,"/%.$","") + i = i - 1 + end + if #newelements == 0 then + return "." + elseif find(str,"^/") then + return "/" .. concat(newelements,'/') + else + return concat(newelements, '/') end - if str == "" then str = "." end - return str end --~ print(file.collapse_path("/a")) diff --git a/Master/texmf-dist/scripts/context/stubs/mswin/mtxrun.lua b/Master/texmf-dist/scripts/context/stubs/mswin/mtxrun.lua index d6b2d13a71a..574335c58d5 100755 --- a/Master/texmf-dist/scripts/context/stubs/mswin/mtxrun.lua +++ b/Master/texmf-dist/scripts/context/stubs/mswin/mtxrun.lua @@ -2223,22 +2223,52 @@ end -- we can hash them weakly + +local insert = table.insert + function file.collapse_path(str) + if str == "" or str =="." then + return "." + elseif find(str,"^%.%.") then + return str + elseif not find(str,"%.") then + return str + end + str = gsub(str,"^%./",lfs.currentdir() .. "/") -- ./xx in qualified str = gsub(str,"\\","/") - if find(str,"/") then - str = gsub(str,"^%./",(gsub(lfs.currentdir(),"\\","/")) .. "/") -- ./xx in qualified - str = gsub(str,"/%./","/") - local n, m = 1, 1 - while n > 0 or m > 0 do - str, n = gsub(str,"[^/%.]+/%.%.$","") - str, m = gsub(str,"[^/%.]+/%.%./","") + local oldelements = checkedsplit(str,"/") + local newelements = { } + local i = #oldelements + while i > 0 do + local element = oldelements[i] + if element == '.' then + -- do nothing + elseif element == '..' then + local n = i -1 + while n > 0 do + local element = oldelements[n] + if element ~= '..' and element ~= '.' then + oldelements[n] = '.' + break + else + n = n - 1 + end + end + if n<1 then + insert(newelements,1,'..') + end + elseif element ~= "" then + insert(newelements,1,element) end - str = gsub(str,"([^/])/$","%1") - -- str = gsub(str,"^%./","") -- ./xx in qualified - str = gsub(str,"/%.$","") + i = i - 1 + end + if #newelements == 0 then + return "." + elseif find(str,"^/") then + return "/" .. concat(newelements,'/') + else + return concat(newelements, '/') end - if str == "" then str = "." end - return str end --~ print(file.collapse_path("/a")) diff --git a/Master/texmf-dist/scripts/context/stubs/unix/luatools b/Master/texmf-dist/scripts/context/stubs/unix/luatools index 581ba70c86a..ac1e38f4c6d 100755 --- a/Master/texmf-dist/scripts/context/stubs/unix/luatools +++ b/Master/texmf-dist/scripts/context/stubs/unix/luatools @@ -2214,22 +2214,52 @@ end -- we can hash them weakly + +local insert = table.insert + function file.collapse_path(str) + if str == "" or str =="." then + return "." + elseif find(str,"^%.%.") then + return str + elseif not find(str,"%.") then + return str + end + str = gsub(str,"^%./",lfs.currentdir() .. "/") -- ./xx in qualified str = gsub(str,"\\","/") - if find(str,"/") then - str = gsub(str,"^%./",(gsub(lfs.currentdir(),"\\","/")) .. "/") -- ./xx in qualified - str = gsub(str,"/%./","/") - local n, m = 1, 1 - while n > 0 or m > 0 do - str, n = gsub(str,"[^/%.]+/%.%.$","") - str, m = gsub(str,"[^/%.]+/%.%./","") + local oldelements = checkedsplit(str,"/") + local newelements = { } + local i = #oldelements + while i > 0 do + local element = oldelements[i] + if element == '.' then + -- do nothing + elseif element == '..' then + local n = i -1 + while n > 0 do + local element = oldelements[n] + if element ~= '..' and element ~= '.' then + oldelements[n] = '.' + break + else + n = n - 1 + end + end + if n<1 then + insert(newelements,1,'..') + end + elseif element ~= "" then + insert(newelements,1,element) end - str = gsub(str,"([^/])/$","%1") - -- str = gsub(str,"^%./","") -- ./xx in qualified - str = gsub(str,"/%.$","") + i = i - 1 + end + if #newelements == 0 then + return "." + elseif find(str,"^/") then + return "/" .. concat(newelements,'/') + else + return concat(newelements, '/') end - if str == "" then str = "." end - return str end --~ print(file.collapse_path("/a")) diff --git a/Master/texmf-dist/scripts/context/stubs/unix/mtxrun b/Master/texmf-dist/scripts/context/stubs/unix/mtxrun index d6b2d13a71a..574335c58d5 100755 --- a/Master/texmf-dist/scripts/context/stubs/unix/mtxrun +++ b/Master/texmf-dist/scripts/context/stubs/unix/mtxrun @@ -2223,22 +2223,52 @@ end -- we can hash them weakly + +local insert = table.insert + function file.collapse_path(str) + if str == "" or str =="." then + return "." + elseif find(str,"^%.%.") then + return str + elseif not find(str,"%.") then + return str + end + str = gsub(str,"^%./",lfs.currentdir() .. "/") -- ./xx in qualified str = gsub(str,"\\","/") - if find(str,"/") then - str = gsub(str,"^%./",(gsub(lfs.currentdir(),"\\","/")) .. "/") -- ./xx in qualified - str = gsub(str,"/%./","/") - local n, m = 1, 1 - while n > 0 or m > 0 do - str, n = gsub(str,"[^/%.]+/%.%.$","") - str, m = gsub(str,"[^/%.]+/%.%./","") + local oldelements = checkedsplit(str,"/") + local newelements = { } + local i = #oldelements + while i > 0 do + local element = oldelements[i] + if element == '.' then + -- do nothing + elseif element == '..' then + local n = i -1 + while n > 0 do + local element = oldelements[n] + if element ~= '..' and element ~= '.' then + oldelements[n] = '.' + break + else + n = n - 1 + end + end + if n<1 then + insert(newelements,1,'..') + end + elseif element ~= "" then + insert(newelements,1,element) end - str = gsub(str,"([^/])/$","%1") - -- str = gsub(str,"^%./","") -- ./xx in qualified - str = gsub(str,"/%.$","") + i = i - 1 + end + if #newelements == 0 then + return "." + elseif find(str,"^/") then + return "/" .. concat(newelements,'/') + else + return concat(newelements, '/') end - if str == "" then str = "." end - return str end --~ print(file.collapse_path("/a")) diff --git a/Master/texmf-dist/tex/context/base/l-file.lua b/Master/texmf-dist/tex/context/base/l-file.lua index 2bfc0709007..52e8ed1fbfd 100644 --- a/Master/texmf-dist/tex/context/base/l-file.lua +++ b/Master/texmf-dist/tex/context/base/l-file.lua @@ -140,22 +140,52 @@ end -- we can hash them weakly + +local insert = table.insert + function file.collapse_path(str) + if str == "" or str =="." then + return "." + elseif find(str,"^%.%.") then + return str + elseif not find(str,"%.") then + return str + end + str = gsub(str,"^%./",lfs.currentdir() .. "/") -- ./xx in qualified str = gsub(str,"\\","/") - if find(str,"/") then - str = gsub(str,"^%./",(gsub(lfs.currentdir(),"\\","/")) .. "/") -- ./xx in qualified - str = gsub(str,"/%./","/") - local n, m = 1, 1 - while n > 0 or m > 0 do - str, n = gsub(str,"[^/%.]+/%.%.$","") - str, m = gsub(str,"[^/%.]+/%.%./","") + local oldelements = checkedsplit(str,"/") + local newelements = { } + local i = #oldelements + while i > 0 do + local element = oldelements[i] + if element == '.' then + -- do nothing + elseif element == '..' then + local n = i -1 + while n > 0 do + local element = oldelements[n] + if element ~= '..' and element ~= '.' then + oldelements[n] = '.' + break + else + n = n - 1 + end + end + if n<1 then + insert(newelements,1,'..') + end + elseif element ~= "" then + insert(newelements,1,element) end - str = gsub(str,"([^/])/$","%1") - -- str = gsub(str,"^%./","") -- ./xx in qualified - str = gsub(str,"/%.$","") + i = i - 1 + end + if #newelements == 0 then + return "." + elseif find(str,"^/") then + return "/" .. concat(newelements,'/') + else + return concat(newelements, '/') end - if str == "" then str = "." end - return str end --~ print(file.collapse_path("/a")) |