improve file remap regex matching

Signed-off-by: kim (grufwub) <grufwub@gmail.com>
This commit is contained in:
kim (grufwub) 2020-05-12 14:04:16 +01:00
parent d927113b42
commit 5aa62ebfa7
3 changed files with 5 additions and 5 deletions

View File

@ -53,7 +53,7 @@ func (fs *FileSystem) RemapRequestPath(requestPath *RequestPath) (*RequestPath,
/* Create new path from template and submatches */
newPath := make([]byte, 0)
for _, submatches := range remap.Regex.FindAllStringSubmatchIndex(requestPath.Selector(), -1) {
for _, submatches := range remap.Regex.FindAllStringSubmatchIndex(requestPath.Relative(), -1) {
newPath = remap.Regex.ExpandString(newPath, remap.Template, requestPath.Relative(), submatches)
}

View File

@ -72,7 +72,6 @@ func setupServer() []*GophorListener {
/* File system */
fileMonitorFreq := flag.Duration("file-monitor-freq", time.Second*60, "Change file monitor frequency.")
fileRemaps := flag.String("file-remap", "", "New-line separated list of file remappings of format: /virtual/relative/path -> /actual/relative/path")
/* Cache settings */
cacheSize := flag.Int("cache-size", 50, "Change file cache size, measured in file count.")
@ -88,6 +87,7 @@ func setupServer() []*GophorListener {
/* Regex */
restrictedFiles := flag.String("restrict-files", "", "New-line separated list of regex statements restricting accessible files.")
fileRemaps := flag.String("file-remap", "", "New-line separated list of file remappings of format: /virtual/relative/path -> /actual/relative/path")
/* User supplied caps.txt information */
serverDescription := flag.String("description", "Gophor, a Gopher server in Go.", "Change server description in generated caps.txt.")

View File

@ -11,8 +11,8 @@ const (
)
type FileRemap struct {
Regex *regexp.Regexp
Template string
Regex *regexp.Regexp
Template string
}
/* Compile a user supplied new line separated list of regex statements */
@ -60,7 +60,7 @@ func compileUserRemapRegex(remaps string) []*FileRemap {
}
/* Try compile regex */
regex, err := regexp.Compile(strings.TrimPrefix(split[0], "/"))
regex, err := regexp.Compile("(?m)"+strings.TrimPrefix(split[0], "/")+"$")
if err != nil {
log.Fatalf("Failed compiling user supplied regex: %s\n", expr)
}