public

diff for recreating an apparent bug in from_json under Perl Dancer

  • Download Gist
Dancer diff for from_json utf8 bug
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
diff -r MyWeb-App/lib/MyWeb/App.pm MyWeb-App-2/lib/MyWeb/App.pm
3c3
<
---
> set serializer => 'JSON';
9a10,14
> post '/test/' => sub {
> my $data = from_json( param('json'), {utf8 => 0});
> return { msg => $data->{q} }
> };
>
10a16
>
diff -r MyWeb-App/views/index.tt MyWeb-App-2/views/index.tt
1,148c1,16
<
< <!--
< Credit goes to the Ruby on Rails team for this page
< has been heavily based on the default Rails page that is
< built with a scaffolded application.
<
< Thanks a lot to them for their work.
<
< See Ruby on Rails if you want a kickass framework in Ruby:
< http://www.rubyonrails.org/
< -->
<
< <div id="page">
< <div id="sidebar">
< <ul id="sidebar-items">
< <li>
< <h3>Join the community</h3>
< <ul class="links">
<
< <li><a href="http://perldancer.org/">PerlDancer</a></li>
< <li><a href="http://twitter.com/PerlDancer/">Official Twitter</a></li>
< <li><a href="http://github.com/sukria/Dancer/">GitHub Community</a></li>
< </ul>
< </li>
<
< <li>
< <h3>Browse the documentation</h3>
<
< <ul class="links">
< <li><a
< href="http://search.cpan.org/dist/Dancer/lib/Dancer/Introduction.pod">Introduction</a></li>
< <li><a href="http://search.cpan.org/dist/Dancer/lib/Dancer/Cookbook.pod">Cookbook</a></li>
< <li><a href="http://search.cpan.org/dist/Dancer/lib/Dancer/Deployment.pod">Deployment Guide</a></li>
< <li><a
< href="http://search.cpan.org/dist/Dancer/lib/Dancer/Tutorial.pod"
< title="a tutorial to build a small blog engine with Dancer">Tutorial</a></li>
< </ul>
< </li>
<
< <li>
< <h3>Your application's environment</h3>
<
< <ul>
< <li>Location: <code>/cygdrive/r/daniel/cwlc/test/MyWeb-App</code></li>
< <li>Template engine: <code><% settings.template %></code></li>
< <li>Logger: <code><% settings.logger %></code></li>
< <li>Environment: <code><% settings.environment %></code></li>
< </ul>
<
< </li>
< </ul>
<
< </div>
<
< <div id="content">
< <div id="header">
< <h1>Perl is dancing</h1>
< <h2>You&rsquo;ve joined the dance floor!</h2>
< </div>
<
< <div id="getting-started">
< <h1>Getting started</h1>
< <h2>Here&rsquo;s how to get dancing:</h2>
<
< <h3><a href="#" id="about_env_link">About your application's environment</a></h3>
<
< <div id="about-content" style="display: none;">
< <table>
< <tbody>
< <tr>
< <td>Perl version</td>
< <td><tt><% perl_version %></tt></td>
< </tr>
< <tr>
< <td>Dancer version</td>
< <td><tt><% dancer_version %></tt></td>
< </tr>
< <tr>
< <td>Backend</td>
< <td><tt><% settings.apphandler %></tt></td>
< </tr>
< <tr>
< <td>Appdir</td>
< <td><tt>/cygdrive/r/daniel/cwlc/test/MyWeb-App</tt></td>
< </tr>
< <tr>
< <td>Template engine</td>
< <td><tt><% settings.template %></tt></td>
< </tr>
< <tr>
< <td>Logger engine</td>
< <td><tt><% settings.logger %></tt></td>
< </tr>
< <tr>
< <td>Running environment</td>
< <td><tt><% settings.environment %></tt></td>
< </tr>
< </tbody>
< </table>
< </div>
<
< <script type="text/javascript">
< $('#about_env_link').click(function() {
< $('#about-content').slideToggle('fast', function() {
< // ok
< });
< return( false );
< });
< </script>
<
<
< <ol>
< <li>
< <h2>Tune your application</h2>
<
< <p>
< Your application is configured via a global configuration file,
< <tt>config.yml</tt> and an "environment" configuration file,
< <tt>environments/development.yml</tt>. Edit those files if you
< want to change the settings of your application.
< </p>
< </li>
<
< <li>
< <h2>Add your own routes</h2>
<
< <p>
< The default route that displays this page can be removed,
< it's just here to help you get started. The template used to
< generate this content is located in
< <code>views/index.tt</code>.
< You can add some routes to <tt>lib/MyWeb/App.pm</tt>.
< </p>
< </li>
<
< <li>
< <h2>Enjoy web development again</h2>
<
< <p>
< Once you've made your changes, restart your standalone server
< (bin/app.pl) and you're ready to test your web application.
< </p>
< </li>
<
< </ol>
< </div>
< </div>
< </div>
---
> <input id="q" value="caf&eacute;"/>
> <button onclick="
> $.ajax({
> url: '/test/',
> type: 'POST',
> data: {
> 'json': JSON.stringify(
> { 'q': $('#q').val() }
> ),
> },
> dataType: 'json',
> success: function(data) {
> alert (data.msg);
> }
> });
> ">Press Me!</button>
\ No newline at end of file

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.