Created
July 7, 2011 14:57
-
-
Save snay2/1069690 to your computer and use it in GitHub Desktop.
Demonstrates a bug in the JSON parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ruleset a163x125 { | |
| meta { | |
| name "JSON parser bug" | |
| description << | |
| Demonstrates a bug in the JSON parser | |
| >> | |
| author "Steve Nay" | |
| logging off | |
| } | |
| dispatch {} | |
| global {} | |
| rule get_raw { | |
| select when pageview ".*" | |
| pre { | |
| webservice = "https://soaregistry.byu.edu/services/catalog_vs0/search/?format=json&field=isbn&terms=0672330768"; | |
| request = http:get(webservice); | |
| content = request.pick("content"); | |
| } | |
| append("body", "<hr />Original content:<br /><textarea cols=80 rows=10>#{content}</textarea>"); | |
| fired { | |
| raise explicit event content_ready with content=content; | |
| } | |
| } | |
| rule no_wrapping { | |
| select when explicit content_ready | |
| pre { | |
| content = event:param("content"); | |
| results = content.decode(); | |
| } | |
| { | |
| emit <| console.log(results); |>; | |
| append("body", "<hr />Not wrapped:<br /><textarea cols=80 rows=10>#{results}</textarea>"); | |
| } | |
| } | |
| rule with_wrapping { | |
| select when explicit content_ready | |
| pre { | |
| content = event:param("content"); | |
| results = '{"records": #{content}}'.decode(); | |
| } | |
| { | |
| emit <| console.log(results); |>; | |
| append("body", "<hr />Wrapped:<br /><textarea cols=80 rows=10>#{results}</textarea>"); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment