PageRenderTime 28ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/_octopress/source/functions/strip_tags/_comments.html

https://gitlab.com/orvi2014/phpjs
HTML | 343 lines | 255 code | 87 blank | 1 comment | 0 complexity | e0637dfe231668ac9e53ba9aa1a9b033 MD5 | raw file
  1. <!-- Generated by Rakefile:build -->
  2. <strong>
  3. <a href="http://an3m1.com/" rel="nofollow">????? ?????? ? ?????</a>
  4. </strong>
  5. on 2012-04-04 14:33:20 <br />
  6. I wonder how you got so good. HaHa ! This is really a fascinating blog, lots of stuff that I can get into. One thing I just want to say is that your design is so perfect ! You certainly know how to get a girls attention ! Im glad that youre here. I feel like Ive learned something new by being here
  7. <hr />
  8. <strong>
  9. Roger
  10. </strong>
  11. on 2012-03-28 05:16:43 <br />
  12. Awesome &amp; thanks!
  13. <hr />
  14. <strong>
  15. <a href="jkhvkjb" rel="nofollow">sacdmn sda.m,c nads,.cn n65467289376541248321908643218694321</a>
  16. </strong>
  17. on 2011-03-31 09:29:16 <br />
  18. !@#$%^&amp;*())(*&amp;^%$#@
  19. <hr />
  20. <strong>
  21. <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a>
  22. </strong>
  23. on 2010-09-08 20:06:17 <br />
  24. @ Chris: Sorry, if the comment system is letting you down here, could you try pasting to pastebin.org?
  25. @ Evertjan Garretsen: Looks like the PHP version needs you to explicitly put br/ in the list of allowed tags
  26. @ Rafał Kukawski: Sublime man. In fact your creation's so good that it's better than PHP's version. Have a look at example 6 and you will see that PHP (5.3.2) will require you to explicitly name br/ in the allow list.
  27. I'm still including your version in php.js, though, as I don't think this will cause bad bugs for people (seems like if you're whitelisting br you intend to whitelist br/ as well) so we can fix it later on.
  28. https://github.com/kvz/phpjs/commit/526ac02243899b12cd0929c0a25133304525c0e8
  29. <hr />
  30. <strong>
  31. Evertjan Garretsen
  32. </strong>
  33. on 2010-09-07 23:14:41 <br />
  34. I discovered that when i allow br, this wil not allow the xhtml closed br like: &lt;br/&gt;. Maybe the following line should be added?
  35. <pre><code>
  36. if (i != 0) { i = html.toLowerCase().indexOf('&lt;'+allowed_tag+'/&gt;');}
  37. </code></pre>
  38. <hr />
  39. <strong>
  40. <a href="http://blog.kukawski.pl" rel="nofollow">Rafa? Kukawski</a>
  41. </strong>
  42. on 2010-07-15 12:02:30 <br />
  43. I extended my previous solution with removing comments and php tags. May not be perfect, but should work for most cases
  44. <pre><code>function strip_tags(input, allowed){
  45. allowed = (((allowed || &quot;&quot;) + &quot;&quot;)
  46. .toLowerCase()
  47. .match(/&lt;[a-z][a-z0-9]*&gt;/g) || [])
  48. .join(''); // making sure the allowed arg is a string containing only tags in lowercase (&lt;a&gt;&lt;b&gt;&lt;c&gt;)
  49. var tags = /&lt;\/?([a-z][a-z0-9]*)\b[^&gt;]*&gt;/gi,
  50. commentsAndPhpTags = /&lt;!--[\s\S]*?--&gt;|&lt;\?(?:php)?[\s\S]*?\?&gt;/gi;
  51. return input.replace(commentsAndPhpTags, '').replace(tags, function($0, $1){
  52. return allowed.indexOf('&lt;' + $1.toLowerCase() + '&gt;') &gt; -1 ? $0 : '';
  53. });
  54. }</code></pre>
  55. <hr />
  56. <strong>
  57. <a href="http://blog.kukawski.pl" rel="nofollow">Rafa? Kukawski</a>
  58. </strong>
  59. on 2010-07-15 08:39:26 <br />
  60. Maybe sth like this?
  61. <pre><code>function strip_tags(input, allowed){
  62. allowed = (((allowed || &quot;&quot;) + &quot;&quot;)
  63. .toLowerCase()
  64. .match(/&lt;[a-z][a-z0-9]*&gt;/g) || [])
  65. .join(''); // making sure the allowed arg is a string containing only tags in lowercase (&lt;a&gt;&lt;b&gt;&lt;c&gt;)
  66. var reg = /(&lt;\/?([a-z][a-z0-9]*)\b[^&gt;]*&gt;)/gi;
  67. return input.replace(reg, function($0, $1, $2){
  68. return allowed.indexOf('&lt;' + $2.toLowerCase() + '&gt;') &gt; -1 ? $0 : '';
  69. });
  70. }</code></pre>
  71. <hr />
  72. <strong>
  73. Chris
  74. </strong>
  75. on 2010-07-14 10:18:52 <br />
  76. Hey,
  77. I have a slight problem with html comments. See this example:
  78. <pre><code>&lt;h2 class=&quot;error&quot;&gt;Ooops, das hätte nicht passieren dürfen!&lt;/h2&gt;
  79. &lt;div class=&quot;graybox&quot;&gt;
  80. Die angegebene Adresse ist mit Ihren Benutzerrechten nicht erreichbar.&lt;br /&gt;
  81. &lt;!--Sie werden in &lt;strong id=&quot;cnt&quot;&gt;&amp;nbsp;&lt;/strong&gt; Sekunden zur Startseite weitergeleitet...--&gt;
  82. &lt;/div&gt;</code></pre>
  83. JS result:
  84. <pre><code>Ooops, das hätte nicht passieren dürfen! Die angegebene Adresse ist mit Ihren Benutzerrechten nicht erreichbar. &amp;nbsp; Sekunden zur Startseite weitergeleitet...--&gt;</code></pre>
  85. See missing &quot;Sie werden in&quot; and additional &quot;--&gt;&quot; in the JS result.
  86. <hr />
  87. <strong>
  88. <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a>
  89. </strong>
  90. on 2009-08-04 12:30:14 <br />
  91. @ Brett Zamir: Ok provided an additional fix. After comment caches clear we should be able to review the results.
  92. <hr />
  93. <strong>
  94. <a href="http://brett-zamir.me" rel="nofollow">Brett Zamir</a>
  95. </strong>
  96. on 2009-07-29 03:06:44 <br />
  97. @Kevin: Thanks for the security fix, and sorry I'm too busy to look into it myself at the moment, but now the code snippets are showing less-than signs, etc. in entity form...
  98. <hr />
  99. <strong>
  100. <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a>
  101. </strong>
  102. on 2009-07-24 12:29:04 <br />
  103. @ Tomasz Wesolowski: Very kind of you to provide the fix! I've added it to SVN along with the credits.
  104. PS: oops indeed! fixed the comment issue
  105. <hr />
  106. <strong>
  107. Tomasz Wesolowski
  108. </strong>
  109. on 2009-07-22 15:39:08 <br />
  110. Oops, no HTML escaping in posts? Here's a cleaner repost:
  111. ---
  112. That's some useful code. :)
  113. Unfortunately it seems to fail on header tags h1..h7. I have probably fixed that by changing the line 42:
  114. <pre><code>// Build allowes tags associative array
  115. if (allowed_tags) {
  116. allowed_array = allowed_tags.match(/([a-zA-Z]+)/gi);
  117. }</code></pre>
  118. to
  119. <pre><code>allowed_array = allowed_tags.match(/([a-zA-Z0-9]+)/gi);</code></pre>
  120. <hr />
  121. <strong>
  122. Tomasz Wesolowski
  123. </strong>
  124. on 2009-07-22 15:37:14 <br />
  125. That's some useful code. :)
  126. Unfortunately it seems to fail on header tags &lt;h1&gt;..&lt;h7&gt;. I have probably fixed that by changing the line 42:
  127. // Build allowes tags associative array
  128. <pre><code>if (allowed_tags) {
  129. allowed_array = allowed_tags.match(/([a-zA-Z]+)/gi);
  130. }</code></pre>
  131. to
  132. <pre><code>allowed_array = allowed_tags.match(/([a-zA-Z0-9]+)/gi);</code></pre>
  133. <hr />
  134. <strong>
  135. <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a>
  136. </strong>
  137. on 2009-03-22 18:55:32 <br />
  138. @ Bobby Drake: Thanks for pointing that out. I fixed the bug and added your testcase to prevent future bugs. Thanks!
  139. <hr />
  140. <strong>
  141. Michael Grier
  142. </strong>
  143. on 2009-03-04 20:46:13 <br />
  144. what does !! do here? validate? convert int to bool?
  145. array unique is using this function internally, but array_unique is not working for me (it returns undefined), and I'm trying to figure out why.
  146. <hr />
  147. <strong>
  148. <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a>
  149. </strong>
  150. on 2009-03-02 14:39:39 <br />
  151. @ Eric Nagel: Great, thanks for pointing that out!
  152. <hr />
  153. <strong>
  154. <a href="http://www.ericnagel.com/" rel="nofollow">Eric Nagel</a>
  155. </strong>
  156. on 2009-02-27 22:05:14 <br />
  157. Thanks for the function. I added:
  158. <pre><code>
  159. var k = '', i = 0;
  160. </code></pre>
  161. in your variable declarations, as I was using k and i outside the function, which put things into a nasty loop. Hope this helps someone.
  162. <hr />
  163. <strong>
  164. <a href="http://computerzworld.com" rel="nofollow">Computerzworld</a>
  165. </strong>
  166. on 2009-01-24 06:36:43 <br />
  167. You have a great collection of PHP equivalent javascript functions. This is really helpful to develpers. Thanks for sharing.
  168. <hr />
  169. <strong>
  170. <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a>
  171. </strong>
  172. on 2008-11-18 12:27:39 <br />
  173. @ Marc Palau: That was a bit of legacy you spotted there, removed it. thx!
  174. <hr />
  175. <strong>
  176. <a href="http://www.nbsp.es" rel="nofollow">Marc Palau</a>
  177. </strong>
  178. on 2008-11-18 10:50:12 <br />
  179. Why is defined allowed_keys??
  180. <pre><code>var allowed_keys = {};</code></pre>
  181. <hr />
  182. <strong>
  183. <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a>
  184. </strong>
  185. on 2008-10-21 10:07:37 <br />
  186. @ Alex: I wasn't aware of this implementation. And, you're right: it is our objective to mimic php as much as reasonably possible. Thanks for sharing, I've updated the function and credited you accordingly.
  187. <hr />
  188. <strong>
  189. <a href="http://deliciousdemon.com" rel="nofollow">Alex</a>
  190. </strong>
  191. on 2008-10-20 21:02:54 <br />
  192. It looks like there's a small difference in your JS implementation of strip_tags from PHP's implementation:
  193. PHP declares multiple allowable tags like this: strip_tags('&amp;lt;p&amp;gt;&amp;lt;b&amp;gt;text&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt;', '&amp;lt;p&amp;gt;&amp;lt;b&amp;gt;')
  194. The JS version is like this:
  195. strip_tags('&amp;lt;p&amp;gt;&amp;lt;b&amp;gt;text&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt;', '&amp;lt;p&amp;gt;,&amp;lt;b&amp;gt;')
  196. Note the comma separation in the JS version between the allowable tags. It's not a big deal, but I thought I'd point it out, as it tripped me up for a while (and I thought you'd want to know since you're attempting to make these functions work syntactically the same as their PHP equivalents). Thanks!
  197. <hr />
  198. <strong>
  199. <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a>
  200. </strong>
  201. on 2008-09-17 13:06:23 <br />
  202. @ Pul: Thank you for pointing that out. I've fixed the code and added your usage example so it will be tested in the future as well.
  203. <hr />
  204. <strong>
  205. Pul
  206. </strong>
  207. on 2008-09-15 15:44:15 <br />
  208. try
  209. <pre><code>
  210. strip_tags(&amp;quot;&amp;lt;a href='index.html'&amp;gt;test&amp;lt;/a&amp;gt;&amp;quot;, &amp;quot;&amp;lt;a&amp;gt;&amp;quot;);
  211. </code></pre>
  212. please fix.. :P
  213. <hr />
  214. <strong>
  215. <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a>
  216. </strong>
  217. on 2008-07-18 09:29:26 <br />
  218. @ Steven Richards: I've made what I think is the right change. Does this work okay?
  219. <hr />
  220. <strong>
  221. Steven Richards
  222. </strong>
  223. on 2008-07-09 03:23:59 <br />
  224. The strip_tags() function appears to be broken in IE7. Upon detecting an opening tag, it completely removes ALL output. The same behavior appears on the test page on this site. It appears that in IE, the match() function returns a copy of the input string and a couple other extraneous values on a successful match, causing the entire string to be replaced by the first matched key (the original input).
  225. To fix, I added this ugly piece of work inside the key loop:
  226. <pre><code>
  227. if (key == '0' || Number(key.toString()))
  228. {
  229. // replacement
  230. }
  231. </code></pre>
  232. <hr />
  233. <strong>
  234. Mohammed
  235. </strong>
  236. on 2008-06-20 06:17:43 <br />
  237. Thanks!
  238. <hr />
  239. <strong>
  240. Rauan
  241. </strong>
  242. on 2008-06-01 21:32:46 <br />
  243. Wow. Thanks, Kevin. That's the very important feature. :)
  244. <hr />
  245. <strong>
  246. <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a>
  247. </strong>
  248. on 2008-05-31 12:33:05 <br />
  249. @ Rauan: PHP.JS is by no means a full PHP implementation in Javascript. But thanks for pointing this out, I've added the functionality
  250. <hr />
  251. <strong>
  252. Rauan
  253. </strong>
  254. on 2008-05-23 23:04:13 <br />
  255. Ok, that's great... But where is exception in regex for allowed_tags?
  256. <hr />