baleezo / google-code-prettify

Automatically exported from code.google.com/p/google-code-prettify
Apache License 2.0
0 stars 0 forks source link

Escape single quotes #144

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I have a small snippet of shell script where I escape a quote. Prettify.js 
thinks I am starting a string.

What steps will reproduce the problem?

Create the following snippet:

<pre class="prettyprint"><code>
#! /bin/sh
# toascii.sh 
for i in $(echo $* | fold -w 1);do 
  printf "%x " \'$i;
done;
echo
</pre></code>

What is the expected output?  What do you see instead?

Expected output:
<span class="pln"><br></span><span class="com">#! /bin/sh</span><span 
class="pln"><br></span><span class="com"># toascii.sh </span><span 
class="pln"><br></span><span class="kwd">for</span><span class="pln"> i 
</span><span class="kwd">in</span><span class="pln"> $</span><span 
class="pun">(</span><span class="pln">echo $</span><span 
class="pun">*</span><span class="pln"> </span><span class="pun">|</span><span 
class="pln"> fold </span><span class="pun">-</span><span class="pln">w 
</span><span class="lit">1</span><span class="pun">);</span><span 
class="kwd">do</span><span class="pln"> <br>&nbsp; printf </span><span 
class="str">"%x "</span><span class="pln"> </span><span 
class="str">\'$i</span><span class="pun">;</span><span 
class="pln"><br></span><span class="kwd">done</span><span 
class="pun">;</span><span class="pln"><br>echo<br></span>

What I see instead:
<span class="pln"><br></span><span class="com">#! /bin/sh</span><span 
class="pln"><br></span><span class="com"># toascii.sh </span><span 
class="pln"><br></span><span class="kwd">for</span><span class="pln"> i 
</span><span class="kwd">in</span><span class="pln"> $</span><span 
class="pun">(</span><span class="pln">echo $</span><span 
class="pun">*</span><span class="pln"> </span><span class="pun">|</span><span 
class="pln"> fold </span><span class="pun">-</span><span class="pln">w 
</span><span class="lit">1</span><span class="pun">);</span><span 
class="kwd">do</span><span class="pln"> <br>&nbsp; printf </span><span 
class="str">"%x "</span><span class="pln"> </span><span 
class="pun">\</span><span class="str">'$i;<br>done;<br>echo<br></span>

What version are you using?  On what browser?

I am using the version dated as of 21-Jul-2010 on Firefox4

Please provide any additional information below.

I guess it should be pretty safe to always escape quotes when outside they are 
preceded by a '\'. I will try to take a look at the code source this weekend 
and see if I can come up with a patch.

Original issue reported on code.google.com by land...@gmail.com on 25 Mar 2011 at 2:13

GoogleCodeExporter commented 8 years ago
Attached a patch that fixes this issue. I checked that it doesn't break any of 
the unit tests.

Original comment by land...@gmail.com on 26 Mar 2011 at 10:16

Attachments:

GoogleCodeExporter commented 8 years ago
Committed your patch at r176.  Thanks.
Testcase at 
http://google-code-prettify.googlecode.com/svn/trunk/tests/prettify_test_2.html#
issue144

Original comment by mikesamuel@gmail.com on 4 Apr 2011 at 5:19