comment_parser icon indicating copy to clipboard operation
comment_parser copied to clipboard

Infinite Loop

Open ghost opened this issue 4 years ago • 2 comments

ff = ''' private String extractFileName(Header header) { if (header != null) { String value = header.getValue(); int start = value.indexOf(FILENAME_HEADER_PREFIX); if (start != -1) { value = value.substring(start + FILENAME_HEADER_PREFIX.length()); int end = value.indexOf('\"'); if (end != -1) { return value.substring(0, end); } } } return null; }'''

xx = comment_parser.extract_comments_from_str(ff,mime='text/x-java-source')

The script seems not able to preprocess this method. Specifically the problematic instruction is the bold one. Do you have any workarounds?

ghost avatar Oct 05 '20 10:10 ghost

There is no infinite loop, the regex used to match literals in C-style code is very computationally expensive.

If you run the script for long enough (or shorten the code) it will eventually pass.

This is a result of https://github.com/jeanralphaviles/comment_parser/commit/7048f63f986fd1319bbd29e5f7952c7c2485997c, where I tweaked the regex to work on escaped strings. I'll have to come up with a less expensive regex.

jeanralphaviles avatar Oct 06 '20 01:10 jeanralphaviles

I confirm that my previously parsed C code can no longer be parsed with comment_parser==v1.2.2 (even after 1 hour)

fcoiffie avatar Nov 03 '20 16:11 fcoiffie