Repository: zaproxy/zaproxy
Issue: HTML / Markdown Report Generation Fails When Path Contains '#'

**Describe the bug**
HTML / Markdown Report Generation fails when the file name or path contains a '#'. XML and JSON reports are generated as expected.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to 'Report'
2. Click on 'Generate HTML Report' or 'Generate Markdown Report'
3. Save the file with a '#' in it's name or path.
4. See error

**Expected behavior**
The report is generated without a problem.

**Software versions**
 - ZAP: 2.9.0
 - OS: Windows 10, Linux
 - Java: openjdk version "11.0.8 2020-07-14"

**Additional context**
Discussed on IRC.

**Would you like to help fix this issue?**
Yes.

Changed files:
zap/src/test/java/org/parosproxy/paros/extension/report/ReportGeneratorUnitTest.java
zap/src/main/java/org/parosproxy/paros/extension/report/ReportGenerator.java

diff --git a/zap/src/main/java/org/parosproxy/paros/extension/report/ReportGenerator.java b/zap/src/main/java/org/parosproxy/paros/extension/report/ReportGenerator.java
index 4665605ff..55d433280 100644
--- a/zap/src/main/java/org/parosproxy/paros/extension/report/ReportGenerator.java
+++ b/zap/src/main/java/org/parosproxy/paros/extension/report/ReportGenerator.java
@@ -31,6 +31,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 // ZAP: 2019/06/01 Normalise line endings.
 // ZAP: 2019/06/05 Normalise format/style.
 // ZAP: 2020/08/06 Issue 6084: Added date time to html report.
+// ZAP: 2020/10/29 Issue 6267: Fix bug to allow writing reports with file path containing '#'.
 package org.parosproxy.paros.extension.report;
 
 import java.io.BufferedReader;
@@ -92,7 +93,7 @@ public class ReportGenerator {
             Transformer transformer = tFactory.newTransformer(stylesource);
 
             // Make the transformation and write to the output file
-            StreamResult result = new StreamResult(outFile);
+            StreamResult result = new StreamResult(outFile.getPath());
             transformer.transform(source, result);
 
         } catch (TransformerException e) {
@@ -132,7 +133,7 @@ public class ReportGenerator {
                 transformer.setParameter("datetime", getCurrentDateTimeString());
 
                 DOMSource source = new DOMSource(doc);
-                StreamResult result = new StreamResult(outfile);
+                StreamResult result = new StreamResult(outfile.getPath());
                 transformer.transform(source, result);
 
             } catch (TransformerException
@@ -311,7 +312,7 @@ public class ReportGenerator {
             transformer.setParameter("datetime", getCurrentDateTimeString());
 
             DOMSource source = new DOMSource(doc);
-            StreamResult result = new StreamResult(outfile);
+            StreamResult result = new StreamResult(outfile.getPath());
             transformer.transform(source, result);
 
         } catch (TransformerException
diff --git a/zap/src/test/java/org/parosproxy/paros/extension/report/ReportGeneratorUnitTest.java b/zap/src/test/java/org/parosproxy/paros/extension/report/ReportGeneratorUnitTest.java
index 82da211b8..3a59b4cea 100644
--- a/zap/src/test/java/org/parosproxy/paros/extension/report/ReportGeneratorUnitTest.java
+++ b/zap/src/test/java/org/parosproxy/paros/extension/report/ReportGeneratorUnitTest.java
@@ -71,6 +71,18 @@ public class ReportGeneratorUnitTest extends TestUtils {
         assertThat(contents(report), is(equalTo("")));
     }
 
+    @Test
+    public void shouldWriteReportWhenPathContainsHashSymbol(@TempDir Path tempDir)
+            throws Exception {
+        // Given
+        String data = "<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><data>ZAP</data>" + NEWLINE;
+        Path report = Files.createTempFile(tempDir, "#", "");
+        // When
+        ReportGenerator.stringToHtml(data, identityXsl(), report.toString());
+        // Then
+        assertThat(contents(report), is(equalTo(data)));
+    }
+
     @Test
     public void shouldUseEmptyArrayForSitesInJsonReportIfNoSitePresent() {
         // Given