Permalink
Browse files

Merge pull request #79 from davidvgalbraith/fix-decrease-next-indent-…

…pattern

decreaseNextIndentPattern: prevent catastrophic backtracking
  • Loading branch information...
svanharmelen committed Jan 10, 2016
2 parents 06a9a20 + 0891ec0 commit 669f1d0c01cc72ccae6661d4540ab354e843d002
Showing with 8 additions and 1 deletion.
  1. +1 −1 settings/language-go.cson
  2. +7 −0 spec/language-go-spec.coffee
@@ -3,4 +3,4 @@
'commentStart': '// '
'increaseIndentPattern': '^.*(\\bcase\\b.*:|\\bdefault\\b:|(\\b(func|if|else|switch|select|for|struct)\\b.*|\\w)\\{[^}]*|\\([^)]*)$'
'decreaseIndentPattern': '^\\s*(\\bcase\\b.*:|\\bdefault\\b:|\\}[),]?|\\)[,]?)$'
- 'decreaseNextIndentPattern': '^\\s*[^\\s()}]+(?<m>[^()]*\\((?:\\g<m>|[^()]*)\\)[^()]*)*[^()]*\\)[,]?$'
+ 'decreaseNextIndentPattern': '^\\s*[^\\s()}]+(?<m>[^()]*\\((?:\\g<m>[^()]*|[^()]*)\\))*[^()]*\\)[,]?$'
@@ -46,7 +46,14 @@ describe 'Go settings', ->
expect(decreaseNextIndentRegex.testSync(' fmt.Println("something"))')).toBeTruthy()
expect(decreaseNextIndentRegex.testSync(' fmt.Println("something")),')).toBeTruthy()
+ expect(decreaseNextIndentRegex.testSync(' fmt.Println("something"), "x"),')).toBeTruthy()
expect(decreaseNextIndentRegex.testSync(' fmt.Println(fmt.Sprint("something"))),')).toBeTruthy()
+ expect(decreaseNextIndentRegex.testSync(' fmt.Println(fmt.Sprint("something"), "x")),')).toBeTruthy()
expect(decreaseNextIndentRegex.testSync(' fmt.Println("something")')).toBeFalsy()
expect(decreaseNextIndentRegex.testSync(' fmt.Println("something"),')).toBeFalsy()
+
+ # a line with many (), testing for catastrophic backtracking.
+ # see https://github.com/atom/language-go/issues/78
+ longLine = 'first.second().third().fourth().fifth().sixth().seventh().eighth().ninth().tenth()'
+ expect(decreaseNextIndentRegex.testSync(longLine)).toBeFalsy()

1 comment on commit 669f1d0

@jlukic

This comment has been minimized.

Show comment
Hide comment

jlukic commented on 669f1d0 Jan 29, 2016

!!!

Please sign in to comment.