You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Andreas Hartmann <an...@apache.org> on 2009/01/21 16:22:22 UTC
Avoid escaping chars in script/style only in HTMLSerializer? (Re:
svn commit: r515096)
Hi Carsten,
cziegeler@apache.org schrieb:
> Author: cziegeler
> Date: Tue Mar 6 04:11:29 2007
> New Revision: 515096
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=515096
> Log:
> Correctly handle content of script and style tag as cdata for html.
is there a particular reason why this change hasn't been applied to the
XHTMLSerializer as well? IIUC, the script/style CDATA handling is also
defined for XHTML [1].
[1] http://www.w3.org/TR/xhtml1/#h-4.8
-- Andreas
>
> Modified:
> cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/HTMLSerializer.java
> cocoon/branches/BRANCH_2_1_X/status.xml
>
> Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/HTMLSerializer.java
> URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/HTMLSerializer.java?view=diff&rev=515096&r1=515095&r2=515096
> ==============================================================================
> --- cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/HTMLSerializer.java (original)
> +++ cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/HTMLSerializer.java Tue Mar 6 04:11:29 2007
> @@ -5,9 +5,9 @@
> * The ASF licenses this file to You under the Apache License, Version 2.0
> * (the "License"); you may not use this file except in compliance with
> * the License. You may obtain a copy of the License at
> - *
> + *
> * http://www.apache.org/licenses/LICENSE-2.0
> - *
> + *
> * Unless required by applicable law or agreed to in writing, software
> * distributed under the License is distributed on an "AS IS" BASIS,
> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> @@ -25,10 +25,10 @@
>
> /**
> * <p>A serializer converting XHTML into plain old HTML.</p>
> - *
> + *
> * <p>For configuration options of this serializer, please look at the
> * {@link XHTMLSerializer} and {@link EncodingSerializer}.</p>
> - *
> + *
> * <p>Any of the XHTML document type declared or used will be converted into
> * its HTML 4.01 counterpart, and in addition to those a "compatible" doctype
> * can be supported to exploit a couple of shortcuts into MSIE's rendering
> @@ -36,16 +36,16 @@
> *
> * <dl>
> * <dt>"<code>none</code>"</dt>
> - * <dd>Not to emit any dococument type declaration.</dd>
> + * <dd>Not to emit any dococument type declaration.</dd>
> * <dt>"<code>compatible</code>"</dt>
> - * <dd>The HTML 4.01 Transitional (exploiting MSIE shortcut).</dd>
> + * <dd>The HTML 4.01 Transitional (exploiting MSIE shortcut).</dd>
> * <dt>"<code>strict</code>"</dt>
> - * <dd>The HTML 4.01 Strict document type.</dd>
> + * <dd>The HTML 4.01 Strict document type.</dd>
> * <dt>"<code>loose</code>"</dt>
> - * <dd>The HTML 4.01 Transitional document type.</dd>
> + * <dd>The HTML 4.01 Transitional document type.</dd>
> * <dt>"<code>frameset</code>"</dt>
> * <dd>The HTML 4.01 Frameset document type.</dd>
> - * </dl>
> + * </dl>
> *
> * @version CVS $Id$
> */
> @@ -74,6 +74,8 @@
>
> private static final HTMLEncoder HTML_ENCODER = new HTMLEncoder();
>
> + protected boolean encodeCharacters = true;
> +
> /**
> * Create a new instance of this <code>HTMLSerializer</code>
> */
> @@ -194,6 +196,10 @@
> length++;
> }
>
> + // script and style are CDATA sections by default, so no encoding
> + if ( "SCRIPT".equals(name) || "STYLE".equals(name) ) {
> + this.encodeCharacters = false;
> + }
> super.startElementImpl(XHTML1_NAMESPACE, name, name, NAMESPACES, at);
> }
>
> @@ -225,6 +231,22 @@
> if (name.equals("META")) return;
> if (name.equals("PARAM")) return;
>
> + // script and style are CDATA sections by default, so no encoding
> + if ( "SCRIPT".equals(name) || "STYLE".equals(name) ) {
> + this.encodeCharacters = true;
> + }
> super.endElementImpl(XHTML1_NAMESPACE, name, name);
> + }
> +
> + /**
> + * Encode and write a specific part of an array of characters.
> + */
> + protected void encode(char data[], int start, int length)
> + throws SAXException {
> + if ( !this.encodeCharacters ) {
> + this.write(data, start, length);
> + return;
> + }
> + super.encode(data, start, length);
> }
> }
>
> Modified: cocoon/branches/BRANCH_2_1_X/status.xml
> URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/status.xml?view=diff&rev=515096&r1=515095&r2=515096
> ==============================================================================
> --- cocoon/branches/BRANCH_2_1_X/status.xml (original)
> +++ cocoon/branches/BRANCH_2_1_X/status.xml Tue Mar 6 04:11:29 2007
> @@ -181,6 +181,9 @@
>
> <changes>
> <release version="2.1.11" date="TBD">
> + <action dev="CZ" type="fix">
> + Serializers block: Correctly handle content of script and style tag as cdata for html.
> + </action>
> <action dev="AG" type="fix" fixes-bug="COCOON-2013" due-to="Larry Ruiz" due-to-email="lruiz@agssa.net">
> CForms: MultivalueEditorWithSuggestion, extended multivalueeditor widget with suggestion list.
> </action>
>
>
>
--
Andreas Hartmann, CTO
BeCompany GmbH
http://www.becompany.ch
Tel.: +41 (0) 43 818 57 01
Re: Avoid escaping chars in script/style only in HTMLSerializer?
(Re: svn commit: r515096)
Posted by Andreas Hartmann <an...@apache.org>.
Antonio Gallardo schrieb:
> Andreas Hartmann escribió:
>> Hi Carsten,
>>
>> cziegeler@apache.org schrieb:
>>> Author: cziegeler
>>> Date: Tue Mar 6 04:11:29 2007
>>> New Revision: 515096
>>>
>>> URL: http://svn.apache.org/viewvc?view=rev&rev=515096
>>> Log:
>>> Correctly handle content of script and style tag as cdata for html.
>> is there a particular reason why this change hasn't been applied to
>> the XHTMLSerializer as well? IIUC, the script/style CDATA handling is
>> also defined for XHTML [1].
>
> I think this is a better solution. Please implement it in this way. Move
> the code from HTMLSerializer to XHTML Serializer. Thanks for taking care
> of this long standing issue.
Thanks for your comment!
I have pulled up the special handling for script/style from the
HTMLSerializer to the XHTMLSerializer in both the 2.1 and 2.2 branch.
-- Andreas
--
Andreas Hartmann, CTO
BeCompany GmbH
http://www.becompany.ch
Tel.: +41 (0) 43 818 57 01
Re: Avoid escaping chars in script/style only in HTMLSerializer?
(Re: svn commit: r515096)
Posted by Antonio Gallardo <ag...@agssa.net>.
Andreas Hartmann escribió:
> Hi Carsten,
>
> cziegeler@apache.org schrieb:
>> Author: cziegeler
>> Date: Tue Mar 6 04:11:29 2007
>> New Revision: 515096
>>
>> URL: http://svn.apache.org/viewvc?view=rev&rev=515096
>> Log:
>> Correctly handle content of script and style tag as cdata for html.
>
> is there a particular reason why this change hasn't been applied to
> the XHTMLSerializer as well? IIUC, the script/style CDATA handling is
> also defined for XHTML [1].
I think this is a better solution. Please implement it in this way. Move
the code from HTMLSerializer to XHTML Serializer. Thanks for taking care
of this long standing issue.
Best Regards,
Antonio Gallardo.
>
> [1] http://www.w3.org/TR/xhtml1/#h-4.8
>
Re: Avoid escaping chars in script/style only in HTMLSerializer?
(Re: svn commit: r515096)
Posted by Carsten Ziegeler <cz...@apache.org>.
Andreas Hartmann schrieb:
> Hi Carsten,
>
> cziegeler@apache.org schrieb:
>> Author: cziegeler
>> Date: Tue Mar 6 04:11:29 2007
>> New Revision: 515096
>>
>> URL: http://svn.apache.org/viewvc?view=rev&rev=515096
>> Log:
>> Correctly handle content of script and style tag as cdata for html.
>
> is there a particular reason why this change hasn't been applied to the
> XHTMLSerializer as well? IIUC, the script/style CDATA handling is also
> defined for XHTML [1].
>
I don't know anymore - we had a discussion about this at that time, and
I think the outcome was to only apply it to the html serializer.
Carsten
--
Carsten Ziegeler
cziegeler@apache.org