Skip to content

Commit

Permalink
Avoid NPE if parameter is missing
Browse files Browse the repository at this point in the history
Refs #48
  • Loading branch information
iamthechad committed Nov 11, 2015
1 parent e468291 commit 92a817d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class RecaptchaService {
return true
}

def success = getRecaptchaInstance().checkAnswer(remoteAddress, params["g-recaptcha-response"].trim())
def success = getRecaptchaInstance().checkAnswer(remoteAddress, params["g-recaptcha-response"]?.trim())
session["recaptcha_error"] = success ? null : true
return success
}
Expand Down
10 changes: 10 additions & 0 deletions test/unit/com/megatome/grails/RecaptchaServiceTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ class RecaptchaServiceTests extends Specification {
service.verifyAnswer([:], "127.0.0.1", [:])
}

// Address issue #48
void "Avoid NPE when g-recaptcha-response parameter is missing"() {
setup:
config.recaptcha.publicKey = "ABC"
config.recaptcha.privateKey = "123"

expect:
!service.verifyAnswer([:], "127.0.0.1", [:])
}

void "test verify answer true"() {
setup:
config.recaptcha.publicKey = "ABC"
Expand Down

0 comments on commit 92a817d

Please sign in to comment.