From 983c94d10a520b89045bd734ca9ff0fa2d1ef0d5 Mon Sep 17 00:00:00 2001 From: maik-s Date: Tue, 25 Apr 2023 20:22:13 +0200 Subject: [PATCH] Update processor.go Fixed a bug where a file extension is always added to the given output file path --- lib/processor.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/processor.go b/lib/processor.go index 4dd2a49..1dca6a3 100644 --- a/lib/processor.go +++ b/lib/processor.go @@ -75,6 +75,15 @@ func (p *Processor) Gowitness() (err error) { return } +//adds the file extension to a given path if the path does not end with the given extension +func addExtensionIfNeeded(filepath, extension string) string { + ext := filepath[len(filepath)-len(extension):] + if ext != extension { + return filepath[:len(filepath)] + extension + } + return filepath +} + // init initialises the Processor func (p *Processor) init() { if p.ScreenshotFileName != "" { @@ -88,9 +97,9 @@ func (p *Processor) init() { // set the extention depending on the screenshot format if p.Chrome.AsPDF { - p.fn = p.fn + ".pdf" + p.fn = addExtensionIfNeeded(p.fn, ".pdf") } else { - p.fn = p.fn + ".png" + p.fn = addExtensionIfNeeded(p.fn, ".png") } p.fp = ScreenshotPath(p.fn, p.URL, p.ScreenshotPath)