Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AlexaOutput throws exception if regex special characters are present in a slot text #1

Open
ryanhollander opened this issue Nov 8, 2016 · 2 comments

Comments

@ryanhollander
Copy link
Contributor

ryanhollander commented Nov 8, 2016

Hi, If I try to build AlexaOutput with a $ symbol in the string, for example: AlexaOutput.ask("UtteranceKey").putSlot("slot1","$5.00"); the handler fails to error state with the exception: "io.klerch.alexa.tellask.util.AlexaRequestHandlerException: General error occured." A little debugging digs up the real issue: "java.lang.indexoutofboundsexception no group 3" which happens in the while loop starting on line 109 of AlexaSpeechletResponse.class in the method resolveSlotsInUtterance. This happens because the regex engine thinks "$5" is a token, it should be escaped before processing.

A workaround is to use "Matcher.quoteReplacement" in the input for the slot, for example:
AlexaOutput.ask("UtteranceKey").putSlot("slot1",Matcher.quoteReplacement("$5.00"));

While the workaround is sufficient for my purposes, it would be great if the library took care of this detail for me and I didn't have to worry about it. Thanks!

@KayLerch
Copy link
Owner

Hi Ryan,
sorry for replying so late. Thanks for pointing this out. I'll consider to add this in an upcoming version of Tellask which will also contain AudioPlayer-features and compatibility with States SDK 1.0.0.
Meanwhile, feel free to contribute your workaround as a PR.

ryanhollander added a commit to ryanhollander/alexa-skills-kit-tellask-java that referenced this issue Feb 5, 2017
Added "Matcher.quoteReplacement" to resolve of slot input in AlexaSpeechletResponse::resolveSlotsInUtterance.
Added test to confirm that slots with replacement text containing $ does not fail with exception
Added entry to utterance.yaml for test
Minor refactor of resolveSlotsInUtterance, broke out double lambda into a lambda & method to improve code readability (see inline comment)
@ryanhollander
Copy link
Contributor Author

Kay, no worries, we are all busy bees. :-) I've submitted a pull request with a fix and test. Hope that helps! Looking forward to the next revision of this SDK, keep up the great work.
My Best,
-Ryan

KayLerch added a commit that referenced this issue Feb 18, 2017
Fixed issue #1 
Thanks a lot Ryan!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants