forked from OWASP/owasp-java-encoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from cnsgithub/kml-encoding-20
resolves OWASP#20 - HTML encoding for KML
- Loading branch information
Showing
6 changed files
with
224 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) 2012 Jeff Ichnowski | ||
// All rights reserved. | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions | ||
// are met: | ||
// | ||
// * Redistributions of source code must retain the above | ||
// copyright notice, this list of conditions and the following | ||
// disclaimer. | ||
// | ||
// * Redistributions in binary form must reproduce the above | ||
// copyright notice, this list of conditions and the following | ||
// disclaimer in the documentation and/or other materials | ||
// provided with the distribution. | ||
// | ||
// * Neither the name of the OWASP nor the names of its | ||
// contributors may be used to endorse or promote products | ||
// derived from this software without specific prior written | ||
// permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
// COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | ||
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
// OF THE POSSIBILITY OF SUCH DAMAGE. | ||
package org.owasp.encoder; | ||
|
||
import java.nio.CharBuffer; | ||
import java.nio.charset.CoderResult; | ||
|
||
/** | ||
* KMLEncoder -- Special case of XML encoding using numeric character entities (e.g. < instead of entity references (e.g. <). | ||
* This encoder should be used instead of {@link XMLEncoder} to address some shortcomings in the KML specification and the way Google Earth (at least the desktop version) interprets HTML. | ||
* | ||
* @see <a href="http://kml4earth.appspot.com/kmlErrata.html?#encoding">KML Reference Errata</a> | ||
* @see <a href="https://github.com/OWASP/owasp-java-encoder/issues/20">OWASP Issue</a> | ||
* | ||
* @author cnsgithub | ||
*/ | ||
class KMLEncoder extends XMLEncoder { | ||
|
||
@Override | ||
protected CoderResult encodeArrays(CharBuffer input, CharBuffer output, boolean endOfInput) { | ||
return super.encodeArrays(input, output, endOfInput, true); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright (c) 2012 Jeff Ichnowski | ||
// All rights reserved. | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions | ||
// are met: | ||
// | ||
// * Redistributions of source code must retain the above | ||
// copyright notice, this list of conditions and the following | ||
// disclaimer. | ||
// | ||
// * Redistributions in binary form must reproduce the above | ||
// copyright notice, this list of conditions and the following | ||
// disclaimer in the documentation and/or other materials | ||
// provided with the distribution. | ||
// | ||
// * Neither the name of the OWASP nor the names of its | ||
// contributors may be used to endorse or promote products | ||
// derived from this software without specific prior written | ||
// permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
// COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | ||
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
// OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
package org.owasp.encoder; | ||
|
||
import junit.framework.Test; | ||
import junit.framework.TestCase; | ||
import junit.framework.TestSuite; | ||
|
||
/** | ||
* KMLEncoderTest -- test suite for the KMLEncoder. | ||
* | ||
* @author cnsgithub | ||
*/ | ||
public class KMLEncoderTest extends TestCase { | ||
|
||
public static Test suite() { | ||
TestSuite suite = new TestSuite(); | ||
EncoderTestSuiteBuilder builder = new EncoderTestSuiteBuilder(new KMLEncoder(), "-safe-", "-&-") | ||
.encode("<strike>foo & bar</strike>", "<strike>foo & bar</strike>") | ||
.encode("invalid-control-characters", " b ", "\0b\26") | ||
.encode("valid-surrogate-pair", "\ud800\udc00", "\ud800\udc00") | ||
.encode("missing-low-surrogate", " ", "\ud800") | ||
.encode("missing-high-surrogate", " ", "\udc00") | ||
.encode("valid-upper-char", "\ufffd", "\ufffd") | ||
.encode("invalid-upper-char", " ", "\uffff") | ||
.invalid(0, 0x1f) | ||
.valid("\t\r\n") | ||
.valid(' ', Character.MAX_CODE_POINT) | ||
.invalid(0x7f, 0x9f) | ||
.valid("\u0085") | ||
.invalid(Character.MIN_SURROGATE, Character.MAX_SURROGATE) | ||
.invalid(0xfdd0, 0xfdef) | ||
.invalid(0xfffe, 0xffff) | ||
.invalid(0x1fffe, 0x1ffff) | ||
.invalid(0x2fffe, 0x2ffff) | ||
.invalid(0x3fffe, 0x3ffff) | ||
.invalid(0x4fffe, 0x4ffff) | ||
.invalid(0x5fffe, 0x5ffff) | ||
.invalid(0x6fffe, 0x6ffff) | ||
.invalid(0x7fffe, 0x7ffff) | ||
.invalid(0x8fffe, 0x8ffff) | ||
.invalid(0x9fffe, 0x9ffff) | ||
.invalid(0xafffe, 0xaffff) | ||
.invalid(0xbfffe, 0xbffff) | ||
.invalid(0xcfffe, 0xcffff) | ||
.invalid(0xdfffe, 0xdffff) | ||
.invalid(0xefffe, 0xeffff) | ||
.invalid(0xffffe, 0xfffff) | ||
.invalid(0x10fffe, 0x10ffff); | ||
|
||
builder.encoded("&><\'\"") | ||
.encode("'", "\'") | ||
.encode(""", "\"") | ||
.encode("safe", "safe"); | ||
|
||
suite.addTest(builder.validSuite().invalidSuite(XMLEncoder.INVALID_CHARACTER_REPLACEMENT).encodedSuite().build()); | ||
return suite; | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -261,8 +261,8 @@ | |
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.5</source> | ||
<target>1.5</target> | ||
<source>1.6</source> | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
cnsgithub
Author
Owner
|
||
<target>1.6</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
|
But aren't there projects that compile using 1.5?