comparison src/luan/host/main.luan @ 1716:b82767112d8e

add String.regex
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 24 Jul 2022 23:43:03 -0600
parents d6a50ed9604f
children 164c6ea53147
comparison
equal deleted inserted replaced
1715:ad44e849c60c 1716:b82767112d8e
5 local ipairs = Luan.ipairs or error() 5 local ipairs = Luan.ipairs or error()
6 local Io = require "luan:Io.luan" 6 local Io = require "luan:Io.luan"
7 local Rpc = require "luan:Rpc.luan" 7 local Rpc = require "luan:Rpc.luan"
8 local Thread = require "luan:Thread.luan" 8 local Thread = require "luan:Thread.luan"
9 local String = require "luan:String.luan" 9 local String = require "luan:String.luan"
10 local regex_quote = String.regex_quote or error()
11 local lower = String.lower or error() 10 local lower = String.lower or error()
12 local matches = String.matches or error() 11 local starts_with = String.starts_with or error()
13 local Hosted = require "luan:host/Hosted.luan" 12 local Hosted = require "luan:host/Hosted.luan"
14 local Logging = require "luan:logging/Logging.luan" 13 local Logging = require "luan:logging/Logging.luan"
15 local logger = Logging.logger "main" 14 local logger = Logging.logger "main"
16 local WebHandler = Hosted.WebHandler or error() 15 local WebHandler = Hosted.WebHandler or error()
17 local Util = require "classpath:luan/host/Util.luan" 16 local Util = require "classpath:luan/host/Util.luan"
111 dir.mkdir() 110 dir.mkdir()
112 return { name = dir.name(), path = dir.to_string(), children = {} } 111 return { name = dir.name(), path = dir.to_string(), children = {} }
113 end 112 end
114 113
115 local function security(site_dir,file) 114 local function security(site_dir,file)
116 matches( file.to_string(), "^"..regex_quote(site_dir.to_string()) ) or error "security violation" 115 starts_with( file.to_string(), site_dir.to_string() ) or error "security violation"
117 end 116 end
118 117
119 function fns.copy_file(domain,password,dir,name,content) 118 function fns.copy_file(domain,password,dir,name,content)
120 local site_dir = get_dir(domain,password) 119 local site_dir = get_dir(domain,password)
121 site_dir or error "domain not found" 120 site_dir or error "domain not found"