Hello,
I have the following inside one of my posts:
<script type="text/javascript" >
$(document).ready(function(){
$('.accordion_teachers').accordion({ collapsible:true, autoHeight:false });
$('.accordion_teachers').accordion('activate', false);
$('.accordion0').click(function(){
$('.accordion_teachers').accordion('activate', 0);
});
$('.accordion1').click(function(){
$('.accordion_teachers').accordion('activate', 1);
});
});
</script>
It's being indexed and displayed (see screenshot).
Is there a way to stop it from indexing code inside the script tags?
Also I just noticed that it indexes stuff between the comment tags:
<!-- *** -->
Is there a way to fix that as well?
Thanks,
Andrey.
Comments
Comment #1
pwolanin commentedWe call filter_xss() on the text before it's indexed. That function should strip HTML comments.
However, filter_xss() will leave behind the content between the script tags - it's assumed that the body is HTML not script. Can you use an API function to put it in the header instead? Or use a block to put it on the page outside the node body?
Comment #2
mr.andrey commentedThe jQuery is specific to that page. It's not being used anywhere else. Although I technically can put it in a block, I would much prefer to leave it in the page itself and avoid the clutter.
Is it possible to have a tag between which everything is omitted? Something like:
That would provide some flexibility in terms of giving the editor ability to exclude things from index.
Odd about filter_xss() and comments. It seems to not be working.
Thanks,
Andrey.
Comment #3
pwolanin commentedI'm not really interested in implementing such a fake tag feature - however, I'd take a patch to strip the content of tags that should never be indexed, e.g. SCRIPT, OBJECT, EMBED, CANVAS, APPLET, AUDIO, VIDEO, PROGRESS, etc.
If the HTML comments are not stripped, that would suggest a core bug?
Comment #4
mr.andrey commentedThis shouldn't be too hard to implement since there is already built-in functionality to weigh certain tags higher than others, right? There is already a way to omit them entirely, so it sounds like this can be as simple as just adding another tag to the list of already existing ones.
I'll tinker around with it.
Odd about the comment thing. Here's the code that leaks through:
I didn't write it and looks like it was copied from a Dreamweaver with embed style setting enabled.
Comment #5
pwolanin commentedNo, this would be new, since filter_xss strips just the tags themselves, not the content inside the tags.
Comment #6
pwolanin commentedIs that comment on multiple lines?
Comment #7
mr.andrey commentednope, one line.
On admin/settings/apachesolr/query-fields there is a setting to omit some of the tags. This wouldn't work the same way?
Comment #8
pwolanin commentedNo, this would not work that way.
Comment #9
pwolanin commentedA quick test locally it seems like the comments are stripped. Can you maybe attach the full text of that node and the details of your input format?
Comment #10
mr.andrey commentedSure.
Input format is Full HTML.
Here is the node body content (it's all on one line):
Comment #11
mr.andrey commentedJust added the contents of apachesolr_clean_text() to node.tpl.php to see what it does:
It outputs this:
Looks like the tags just get converted to html entities.
And here's the output of the $document as it's being indexed (via hook_apachesolr_update_index()):
Comment #12
mr.andrey commentedReplacing
With
Returns
It's checked against the Filtered HTML filter format. This may not be an ideal way of doing it, but it does seem to work in this case.
Comment #13
mr.andrey commentedOK, here's a patch that alters apachesolr_clean_text() and removes:
Including the content these tags contain.
Comment #14
mr.andrey commentedupdated patch to fix the:
issue as well
Comment #15
mr.andrey commentedupdated patch. changed the syntax a bit. added iframe to the list of excluded tags -- youtube now uses iframe for embeds.
Comment #16
mr.andrey commentedweird, last patch didn't come through fully... here it is attached again.
Comment #17
mr.andrey commentedYou won't believe it. Another patch :-)
I realized that filter_xss() strips the script tags leaving the content between them, so the content needs to be intercepted before that happens.
Tested this with the following bits of code:
and
It strips the tags and everything between them.
Comment #18
pwolanin commentedI would suggest instead writing the regex with a capturing pattern and a back reference.
e.g.:
filter_xss() really should be removing the html comments, so I'd rather look into that problem rather than masking it here.
Comment #19
pwolanin commentedComment #20
pwolanin commentedLet's fix in HEAD first.
Comment #21
pwolanin commentedCommitted this to 7.x, needs to be ported.
Comment #22
pwolanin commentedPlease test this patch for 6.x-1.x.
Note that the pattern has the "U" modifier, otherwise it can strip too much.
Comment #23
nick_vhMoving this to 6.x-3.x and closing since feature requests are only for the new version and this is a backport of the 7.x-1.x which basically already has this patch applied. Thanks for all the hard work.