Repository: pydot/pydot (language: python)

Issue:
Bug in quoting node names with periods in v3.0.1
I tried using a test case like this:
```
class WheelTestCase(unittest.TestCase):
    def test_quote_node_id(self):
        g = pydot.Dot()
        g.add_node(pydot.Node("foo.bar"))
        g.add_node(pydot.Node("baz"))
        g.add_edge(pydot.Edge("foo.bar", "baz"))
        self.assertEqual(g.to_string(), 'digraph G {\n"foo.bar";\nbaz;\n"foo.bar" -> baz;\n}\n')
```

That comparison is true in pydot v2.0.0, but in pydot v3.0.1 it does not quote the node ids, resulting in this graph instead:
```
digraph G {
foo.bar;
baz;
foo.bar -> baz;
}
```

I tried parsing this graph with two different Graphviz versions:
* v2.44.0 output: "Error: ./test.dot: syntax error in line 2 near '.'"
* 12.1.1 (20240910.0053): "Error: ./test.dot: syntax error in line 2 near '.'"

This id needs to be quoted, which it was in v2.0.0, but is no longer in v3.0.1



Discussion / hints:
@dulinriley 

Hmm, yep. That's definitely a change.

It looks like, when I fixed the `re_all_numeric` regular expression (which was supposed to detect numeric values, but contained a `,` instead of a `\.` in the matching characters), I **also** changed the `id_re_alpha_nums` and `id_re_alpha_nums_with_ports` REs to allow periods, which they shouldn't. Crap.

And in fact, it seems it was not entirely correct removing the commas, as well. (I did it because they were messing up attribute quoting; things like `style="dashed,bold"` would get inserted as `[style=dashed,bold]` which doesn't work very well.) But when used in ID strings, I've now found that both of these:

```dot
graph G {
a,b [color=red];
c [color=blue];
a,b -- c;
}
```
```dot
graph G {
1.2,3.4 [color=red];
c [color=blue];
1.2,3.4 -- c;
}
```
...produce perfectly valid graphs:

![l](https://github.com/user-attachments/assets/e2fb1830-b1a0-4c72-bfe4-f9f00d8acc00) ![n](https://github.com/user-attachments/assets/131f6ee5-4b24-431f-accb-4f0b2dcb4a77)

However, it doesn't seem to be _wrong_ to quote them, as it doesn't seem to make a difference (luckily!):
```dot
graph G {
"a,b" [color=red];
c [color=blue]; 
"a,b" -- c;
}
```
![q](https://github.com/user-attachments/assets/fada08b3-6523-49e5-a3e4-d7c6daead566)

But, yeah, _not_ quoting **alphanumeric** strings that contain periods is clearly an error that needs to be fixed.

Fix patch:
diff --git a/src/pydot/core.py b/src/pydot/core.py
index 10b8ce54..0ec94a2e 100644
--- a/src/pydot/core.py
+++ b/src/pydot/core.py
@@ -297,9 +297,9 @@ def make_quoted(s):
 re_dbl_quoted = re.compile(r'^".*"$', re.S)
 re_html = re.compile(r"^<.*>$", re.S)
 
-id_re_alpha_nums = re.compile(r"^[_a-zA-Z][a-zA-Z0-9_\.]*$")
+id_re_alpha_nums = re.compile(r"^[_a-zA-Z][a-zA-Z0-9_]*$")
 id_re_alpha_nums_with_ports = re.compile(
-    r'^[_a-zA-Z][a-zA-Z0-9_\.:"]*[a-zA-Z0-9_\."]+$'
+    r'^[_a-zA-Z][a-zA-Z0-9_:"]*[a-zA-Z0-9_"]+$'
 )
 id_re_with_port = re.compile(r"^([^:]*):([^:]*)$")
 


Test patch:
diff --git a/test/test_pydot.py b/test/test_pydot.py
index fa30be0a..25cf05de 100644
--- a/test/test_pydot.py
+++ b/test/test_pydot.py
@@ -429,6 +429,26 @@ def test_alphanum_quoting(self):
                 """),
         )
 
+    def test_alphanum_quoting2(self):
+        """Test the fix for issue #418."""
+        g = pydot.Dot(graph_name="issue418", graph_type="graph")
+        n1 = pydot.Node("foo.bar", color="red")
+        n2 = pydot.Node("baz", color="blue")
+        g.add_node(n1)
+        g.add_node(n2)
+        g.add_edge(pydot.Edge(n1, n2))
+
+        self.assertEqual(
+            g.to_string(),
+            textwrap.dedent("""\
+                graph issue418 {
+                "foo.bar" [color=red];
+                baz [color=blue];
+                "foo.bar" -- baz;
+                }
+                """),
+        )
+
     def test_edge_quoting(self):
         """Test the fix for issue #383 (pydot 3.0.0)."""
         g = pydot.Graph("", graph_type="digraph")