From 87f302b7da775aa4068bd2bb5ce9c24dd01d67e0 Mon Sep 17 00:00:00 2001 From: Michael Camilleri Date: Wed, 12 Jun 2019 14:47:25 +0900 Subject: [PATCH 1/2] Fix shebang regex in Python lexer The Python lexer only supported minor version numbers for shebangs involving `python2`. Minor versions of Python 3 should also be included. This commit corrects that problem and supports minor version numbers higher than 9. This fixes #945. --- lib/rouge/lexers/python.rb | 2 +- spec/lexers/python_spec.rb | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/rouge/lexers/python.rb b/lib/rouge/lexers/python.rb index 8225a26364..3c9ac6a83b 100644 --- a/lib/rouge/lexers/python.rb +++ b/lib/rouge/lexers/python.rb @@ -12,7 +12,7 @@ class Python < RegexLexer mimetypes 'text/x-python', 'application/x-python' def self.detect?(text) - return true if text.shebang?(/pythonw?(3|2(\.\d)?)?/) + return true if text.shebang?(/pythonw?(?:[23](?:\.\d+)?)?$/) end def self.keywords diff --git a/spec/lexers/python_spec.rb b/spec/lexers/python_spec.rb index de0139754d..971bd16a26 100644 --- a/spec/lexers/python_spec.rb +++ b/spec/lexers/python_spec.rb @@ -23,9 +23,11 @@ it 'guesses by source' do assert_guess :source => '#!/usr/bin/env python' - assert_guess :source => '#!/usr/local/bin/python3' assert_guess :source => '#!/usr/bin/python2' assert_guess :source => '#!/usr/bin/python2.7' + assert_guess :source => '#!/usr/local/bin/python3' + assert_guess :source => '#!/usr/local/bin/python3.5' + assert_guess :source => '#!/usr/local/bin/python3.14' deny_guess :source => '#!/usr/bin/env python4' end end From 1330145fd69919f6e2b01c7994db4370dc09f0f9 Mon Sep 17 00:00:00 2001 From: Michael Camilleri Date: Wed, 12 Jun 2019 15:02:15 +0900 Subject: [PATCH 2/2] Remove end of line check --- lib/rouge/lexers/python.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rouge/lexers/python.rb b/lib/rouge/lexers/python.rb index 3c9ac6a83b..72efe1f417 100644 --- a/lib/rouge/lexers/python.rb +++ b/lib/rouge/lexers/python.rb @@ -12,7 +12,7 @@ class Python < RegexLexer mimetypes 'text/x-python', 'application/x-python' def self.detect?(text) - return true if text.shebang?(/pythonw?(?:[23](?:\.\d+)?)?$/) + return true if text.shebang?(/pythonw?(?:[23](?:\.\d+)?)?/) end def self.keywords