all repos — homestead @ fd0f99dffb49f29531d1974a638c0ce883bf5db7

Code for my website

sqlite: fix accidental modification of path when checking

Alan Pearce
commit

fd0f99dffb49f29531d1974a638c0ce883bf5db7

parent

a8319b95f5f2e8ad28f967e6b7534539064c7df2

1 file changed, 9 insertions(+), 4 deletions(-)

changed files
M internal/storage/sqlite/reader.gointernal/storage/sqlite/reader.go
@@ -110,20 +110,25 @@ differs = false
case strings.HasSuffix(path, "/index.html"): cPath, differs = strings.CutSuffix(path, "index.html") case !strings.HasSuffix(path, "/"): - cPath += "/" - err := r.queries.checkPath.QueryRow(cPath).Scan(&differs) + err := r.queries.checkPath.QueryRow(cPath + "/").Scan(&differs) if err != nil { r.log.Warn("error canonicalising path", "path", path, "error", err) return } + if differs { + cPath += "/" + } case strings.HasSuffix(path, "/"): - cPath = strings.TrimSuffix(path, "/") - err := r.queries.checkPath.QueryRow(cPath).Scan(&differs) + tmp := strings.TrimSuffix(path, "/") + err := r.queries.checkPath.QueryRow(tmp).Scan(&differs) if err != nil { r.log.Warn("error canonicalising path", "path", path, "error", err) return + } + if differs { + cPath = tmp } }