Repository: fitbenchmarking/fitbenchmarking

Issue:
Wrong error when the problem name contains special characters 
When testing another bug fix, I found a new bug. 

If I put the following in a problem definition file 

```
name = '$Q = 0.4628 \\AA$'
```

I will always get the error
```
The filepath for saving a file is too long.
Details:
   Please change the results directory so that it is well within the 260 character limit.
```

even if the file path is shorter than other things that do run. Changing the name to
```
name = 'Q = 0.4628 AA'
```
fixes the problem. 

I think we should at least have an error message that reflects the actual error. 

Discussion:
coveralls: 
[![Coverage Status](https://coveralls.io/builds/70630228/badge)](https://coveralls.io/builds/70630228)

coverage: 90.221% (+0.007%) from 90.214%
when pulling **bc8e14f18c924c637d80ddf7366809b3b90b0a50 on RabiyaF:1276-fixed-problem-name-bug**
into **cbbfa71754bb236973ac80ffdf357cf1229ca98c on fitbenchmarking:master**.


Patch:
diff --git a/fitbenchmarking/parsing/fitbenchmark_parser.py b/fitbenchmarking/parsing/fitbenchmark_parser.py
index 78961a35..4f9c03cc 100644
--- a/fitbenchmarking/parsing/fitbenchmark_parser.py
+++ b/fitbenchmarking/parsing/fitbenchmark_parser.py
@@ -236,7 +236,11 @@ class FitbenchmarkParser(Parser):
                 continue
 
             lhs, rhs = line.split("=", 1)
-            entries[lhs.strip()] = rhs.strip().strip('"').strip("'")
+            key = lhs.strip()
+            value = rhs.strip().strip('"').strip("'")
+            if key == 'name':
+                value = re.sub(r"[\\/]", "", value)
+            entries[key] = value
 
         return entries
 


Test patch:
diff --git a/fitbenchmarking/parsing/tests/test_parsers.py b/fitbenchmarking/parsing/tests/test_parsers.py
index 99882ae1..d9f46afb 100644
--- a/fitbenchmarking/parsing/tests/test_parsers.py
+++ b/fitbenchmarking/parsing/tests/test_parsers.py
@@ -7,13 +7,16 @@ from importlib import import_module
 from inspect import getmembers, isabstract, isclass
 from json import load
 from unittest import TestCase
+from unittest.mock import MagicMock, patch
 
 import numpy as np
+from parameterized import parameterized
 from pytest import test_type as TEST_TYPE  # pylint: disable=no-name-in-module
 from scipy.sparse import issparse
 
 from conftest import run_for_test_types
 from fitbenchmarking.parsing.base_parser import Parser
+from fitbenchmarking.parsing.fitbenchmark_parser import FitbenchmarkParser
 from fitbenchmarking.parsing.fitting_problem import FittingProblem
 from fitbenchmarking.parsing.parser_factory import (ParserFactory,
                                                     parse_problem_file)
@@ -556,3 +559,36 @@ class TestParserNoJac(TestCase):
 
                     actual = fitting_problem.jacobian(x, r[1])
                     assert np.isclose(actual, r[2]).all()
+
+
+class TestFitbenchmarkParser(TestCase):
+    """
+    Tests the FitbenchmarkParser.
+    """
+
+    @parameterized.expand([
+        (["name = '\\sample_problem'"],
+         {"name": "sample_problem"}),
+        (["name = 'sample_problem/'"],
+         {"name": "sample_problem"}),
+        (["name = '\\sample_problem/////'"],
+         {"name": "sample_problem"}),
+        (["#fitbenchmarking"], {}),
+        (["name = 'sample_problem' # my important comment"],
+         {"name": "sample_problem"}),
+        (["function = 'Userdefined: a/4 ** 6'"],
+         {"function": "Userdefined: a/4 ** 6"}),
+        (["function = 'Userdefined = a/4 ** 6'"],
+         {"function": "Userdefined = a/4 ** 6"}),
+    ])
+    @patch.object(FitbenchmarkParser, "__init__", lambda a, b, c: None)
+    def test_get_data_problem_entries(self, file_data, expected):
+        """
+        Verifies the output of _get_data_problem_entries() method.
+        """
+        parser = FitbenchmarkParser('test_file.txt', {"parse"})
+        parser.file = MagicMock()
+        parser.file.readlines.return_value = file_data
+        # pylint: disable=protected-access
+        result = parser._get_data_problem_entries()
+        assert result == expected