Hey @g2384,
First of all, thanks for the project. I've found a false-positive when working with the formatter on a school project.
The issue is that -- inside string literals is treated as a comment delimiter. So for example, the string "Hi I am Foo <-- Really Foo" gets corrupted to "Hi I am Foo < -- Really Foo". In my concrete use case the testing logic broke as a result.
When I discovered the issue I was using Visual Studio Code with the VHDL-By-HGB Plugin.
I've added a minimal reproducer below:
entity test is
end entity test;
architecture rtl of test is
constant MSG : string := "This <-- should not happen";
begin
end architecture rtl;
The issue is also reproducible with the web formatter, which I have tested.
This is likely related to: https://github.com/g2384/VHDLFormatter/blob/master/VHDLFormatter.ts#L332
EscapeComments uses a plain indexOf("--") with no awareness of string context, and it runs before string literals are masked by escapeText. This means -- inside any quoted string gets incorrectly treated as a comment start.
The fix would be to escape string literals before calling EscapeComments, so that the content inside quotes is already masked by the time comment scanning runs.
I can open up a PR if you like me to.
Regards,
Alessandro
Hey @g2384,
First of all, thanks for the project. I've found a false-positive when working with the formatter on a school project.
The issue is that
--inside string literals is treated as a comment delimiter. So for example, the string"Hi I am Foo <-- Really Foo"gets corrupted to"Hi I am Foo < -- Really Foo". In my concrete use case the testing logic broke as a result.When I discovered the issue I was using Visual Studio Code with the VHDL-By-HGB Plugin.
I've added a minimal reproducer below:
The issue is also reproducible with the web formatter, which I have tested.
This is likely related to: https://github.com/g2384/VHDLFormatter/blob/master/VHDLFormatter.ts#L332
EscapeCommentsuses a plainindexOf("--")with no awareness of string context, and it runs before string literals are masked byescapeText. This means--inside any quoted string gets incorrectly treated as a comment start.The fix would be to escape string literals before calling
EscapeComments, so that the content inside quotes is already masked by the time comment scanning runs.I can open up a PR if you like me to.
Regards,
Alessandro