Projects
Mega:23.09
jettison
Sign Up
Log In
Username
Password
We truncated the diff of some files because they were too big. If you want to see the full diff for every file,
click here
.
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 3
View file
_service:tar_scm:jettison.spec
Changed
@@ -1,12 +1,11 @@ Name: jettison -Version: 1.3.7 +Version: 1.5.4 Release: 1 Summary: A JSON StAX implementation License: ASL 2.0 URL: https://github.com/codehaus/jettison BuildArch: noarch -Source0: https://github.com/codehaus/jettison/archive/%{name}-%{version}.tar.gz -Patch0: %{name}-update-woodstox-version.patch +Source0: https://github.com/codehaus/jettison/archive/refs/tags/%{name}-%{version}.tar.gz BuildRequires: maven-local mvn(junit:junit) mvn(org.apache.felix:maven-bundle-plugin) BuildRequires: mvn(org.codehaus:codehaus-parent:pom:) BuildRequires: mvn(org.codehaus.woodstox:woodstox-core-asl) mvn(stax:stax-api) @@ -22,11 +21,10 @@ This package contains the API documentation for %{name}. %prep -%setup -q -n %{name}-%{name}-%{version} -%patch0 -p1 -%pom_xpath_remove pom:build/pom:extensions +%autosetup -n %{name}-%{name}-%{version} -p1 %pom_remove_plugin :maven-release-plugin -%pom_xpath_remove pom:Private-Package +%pom_remove_plugin :nexus-staging-maven-plugin +%pom_remove_plugin :maven-enforcer-plugin %build %mvn_build -f @@ -35,11 +33,15 @@ %mvn_install %files -f .mfiles -%doc src/main/resources/META-INF/LICENSE +%license LICENSE %files javadoc -f .mfiles-javadoc -%doc src/main/resources/META-INF/LICENSE +%license LICENSE %changelog +* Thu Dec 07 2023 yaoxin <yao_xin001@hoperun.com> - 1.5.4-1 +- Upgrade to 1.5.4 for fix cves: CVE-2022-40149,CVE-2022-40150, + CVE-2022-45685,CVE-2022-45693 and CVE-2023-1436 + * Sat Aug 1 2020 Jeffery.Gao <gaojianxing@huawei.com> - 1.3.7-1 - Package init
View file
_service:tar_scm:jettison-update-woodstox-version.patch
Deleted
@@ -1,15 +0,0 @@ ---- a/pom.xml -+++ b/pom.xml -@@ -26,9 +26,9 @@ - <version>1.0.1</version> - </dependency> - <dependency> -- <groupId>woodstox</groupId> -- <artifactId>wstx-asl</artifactId> -- <version>3.2.2</version> -+ <groupId>org.codehaus.woodstox</groupId> -+ <artifactId>woodstox-core-asl</artifactId> -+ <version>4.1.2</version> - <scope>test</scope> - </dependency> - </dependencies>
View file
_service
Changed
@@ -2,7 +2,7 @@ <service name="tar_scm"> <param name="url">git@gitee.com:src-openeuler/jettison.git</param> <param name="scm">git</param> - <param name="revision">openEuler-23.09</param> + <param name="revision">master</param> <param name="exclude">*</param> <param name="extract">*</param> </service>
View file
_service:tar_scm:jettison-1.5.4.tar.gz/.github
Added
+(directory)
View file
_service:tar_scm:jettison-1.5.4.tar.gz/.github/workflows
Added
+(directory)
View file
_service:tar_scm:jettison-1.5.4.tar.gz/.github/workflows/codeql-analysis.yml
Added
@@ -0,0 +1,74 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: "master" + pull_request: + # The branches below must be a subset of the branches above + branches: "master" + schedule: + - cron: '38 10 * * 5' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: 'java' + # CodeQL supports 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + # ℹ️ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: "/language:${{matrix.language}}"
View file
_service:tar_scm:jettison-1.5.4.tar.gz/.gitignore
Added
@@ -0,0 +1,18 @@ +.idea/ +.mvn/ +*.iml +*.ipr +*.iws +.DS_Store +.checkstyle +.classpath +.ekstazi +.pmd +.pmdruleset +.pmdruleset.xml +.project +.ruleset +.settings/ +target/ +velocity.log +bin/
View file
_service:tar_scm:jettison-1.5.4.tar.gz/LICENSE
Added
@@ -0,0 +1,202 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed 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.
View file
_service:tar_scm:jettison-1.5.4.tar.gz/README.md
Added
@@ -0,0 +1,13 @@ +Jettison is a Java library for converting XML to JSON and vice-versa with the help of StAX (https://en.wikipedia.org/wiki/StAX). +It implements XMLStreamWriter and XMLStreamReader and supports Mapped and BadgerFish conventions. Latest release is 1.4.0. + +For example, with a Mapped convention, JAXB processes JAXB beans and emits XMLStreamWriter events which are processed by Jettison +with the XML data being converted to JSON. Likewise, when it reads JSON, it reports XMLStreamReader events for JAXB to populate JAXB +beans. + +Note improving and supporting the Mapped convention code is the main focus of this project. However the pull requests from +BadgerFish convention users are welcomed. + +Jettison was originally created by Dan Diephouse and hosted at Codehause. + +
View file
_service:tar_scm:jettison-1.3.7.tar.gz/pom.xml -> _service:tar_scm:jettison-1.5.4.tar.gz/pom.xml
Changed
@@ -2,62 +2,77 @@ <modelVersion>4.0.0</modelVersion> <groupId>org.codehaus.jettison</groupId> <artifactId>jettison</artifactId> - <version>1.3.7</version> + <version>1.5.4</version> <packaging>bundle</packaging> <name>Jettison</name> <description>A StAX implementation for JSON.</description> + <url>https://github.com/jettison-json/jettison</url> <licenses> <license> <name>Apache License, Version 2.0</name> <url>http://www.apache.org/licenses/LICENSE-2.0</url> </license> </licenses> - <parent> - <groupId>org.codehaus</groupId> - <artifactId>codehaus-parent</artifactId> - <version>3</version> - </parent> - <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> - <version>3.8.1</version> + <version>4.13.2</version> <scope>test</scope> </dependency> - <dependency> - <groupId>stax</groupId> - <artifactId>stax-api</artifactId> - <version>1.0.1</version> - </dependency> <dependency> - <groupId>woodstox</groupId> - <artifactId>wstx-asl</artifactId> - <version>3.2.2</version> + <groupId>com.fasterxml.woodstox</groupId> + <artifactId>woodstox-core</artifactId> + <version>6.4.0</version> <scope>test</scope> </dependency> </dependencies> <scm> - <connection>scm:svn:http://svn.codehaus.org/jettison/tags/jettison-1.3.7</connection> - <developerConnection>scm:svn:https://svn.codehaus.org/jettison/tags/jettison-1.3.7</developerConnection> - <url>scm:svn:https://svn.codehaus.org/jettison/tags/jettison-1.3.7</url> + <connection>scm:git:http://github.com/jettison-json/jettison.git</connection> + <developerConnection>scm:git:https://github.com/jettison-json/jettison.git</developerConnection> + <url>https://github.com/jettison-json/jettison</url> + <tag>jettison-1.5.4</tag> </scm> + <distributionManagement> + <snapshotRepository> + <id>ossrh</id> + <url>https://oss.sonatype.org/content/repositories/snapshots</url> + </snapshotRepository> + <repository> + <id>ossrh</id> + <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url> + </repository> + </distributionManagement> <build> - <extensions> - <extension> - <groupId>org.apache.maven.wagon</groupId> - <artifactId>wagon-webdav</artifactId> - <version>1.0-beta-2</version> - </extension> - </extensions> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-enforcer-plugin</artifactId> + <version>3.0.0</version> + <executions> + <execution> + <id>enforce-maven</id> + <goals> + <goal>enforce</goal> + </goals> + <configuration> + <rules> + <requireMavenVersion> + <version>3.2.5</version> + </requireMavenVersion> + </rules> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> + <version>3.10.1</version> <configuration> - <source>1.5</source> - <target>1.5</target> + <source>1.8</source> + <target>1.8</target> <optimize>true</optimize> <debug>true</debug> <showDeprecation>true</showDeprecation> @@ -65,33 +80,107 @@ </configuration> </plugin> <plugin> - <artifactId>maven-release-plugin</artifactId> - <configuration> - <tagBase>https://svn.codehaus.org/jettison/tags/</tagBase> - </configuration> + <groupId>org.sonatype.plugins</groupId> + <artifactId>nexus-staging-maven-plugin</artifactId> + <version>1.6.13</version> + <extensions>true</extensions> + <configuration> + <serverId>ossrh</serverId> + <nexusUrl>https://oss.sonatype.org/</nexusUrl> + <autoReleaseAfterClose>true</autoReleaseAfterClose> + </configuration> </plugin> <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <extensions>true</extensions> - <version>1.0.0</version> + <version>5.1.6</version> <configuration> <instructions> - <Bundle-Name>${artifactId}</Bundle-Name> - <Bundle-SymbolicName>${groupId}.${artifactId}</Bundle-SymbolicName> + <Bundle-Name>${project.artifactId}</Bundle-Name> + <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName> <Export-Package>org.codehaus.jettison*;version=${project.version}</Export-Package> - <Import-Package>*</Import-Package> - <Private-Package>!*</Private-Package> + <Import-Package>javax.xml,*</Import-Package> <Implementation-Title>${project.name}</Implementation-Title> <Implementation-Version>${project.version}</Implementation-Version> + <_versionpolicy>$(version;==;$(@)),$(version;+;$(@)))</_versionpolicy> + <_nouses>true</_nouses> </instructions> </configuration> </plugin> - </plugins> - + <pluginManagement> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-release-plugin</artifactId> + <version>2.5.3</version> + <configuration> + <useReleaseProfile>false</useReleaseProfile> + <preparationGoals>clean install</preparationGoals> + <goals>deploy</goals> + <arguments>-Prelease</arguments> + <autoVersionSubmodules>true</autoVersionSubmodules> + </configuration> + </plugin> + </plugins> + </pluginManagement> </build> - + <profiles> + <profile> + <id>release</id> + <build> + <plugins> + <!-- We want to deploy the artifact to a staging location for perusal --> + <plugin> + <inherited>true</inherited> + <artifactId>maven-deploy-plugin</artifactId> + <version>2.8.2</version> + <configuration> + <altDeploymentRepository>${deploy.altRepository}</altDeploymentRepository> + <updateReleaseInfo>true</updateReleaseInfo> + </configuration> + </plugin> + <!-- We want to sign the artifact, the POM, and all attached artifacts --> + <plugin> + <artifactId>maven-gpg-plugin</artifactId> + <version>3.0.1</version> + <executions> + <execution> + <goals> + <goal>sign</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-source-plugin</artifactId> + <executions> + <execution>
View file
_service:tar_scm:jettison-1.3.7.tar.gz/src/main/java/org/codehaus/jettison/AbstractXMLStreamWriter.java -> _service:tar_scm:jettison-1.5.4.tar.gz/src/main/java/org/codehaus/jettison/AbstractXMLStreamWriter.java
Changed
@@ -82,6 +82,7 @@ /** * @deprecated since 1.2 because of misspelling. Use serializeAsArray(String name) instead. + * @param name the name */ @Deprecated public void seriliazeAsArray(String name) {
View file
_service:tar_scm:jettison-1.3.7.tar.gz/src/main/java/org/codehaus/jettison/badgerfish/BadgerFishXMLStreamWriter.java -> _service:tar_scm:jettison-1.5.4.tar.gz/src/main/java/org/codehaus/jettison/badgerfish/BadgerFishXMLStreamWriter.java
Changed
@@ -119,6 +119,10 @@ } public void writeCharacters(String text) throws XMLStreamException { + text = text.trim(); + if (text.length() == 0) { + return; + } try { Object o = getCurrentNode().opt("$"); if (o instanceof JSONArray) {
View file
_service:tar_scm:jettison-1.3.7.tar.gz/src/main/java/org/codehaus/jettison/json/JSONArray.java -> _service:tar_scm:jettison-1.5.4.tar.gz/src/main/java/org/codehaus/jettison/json/JSONArray.java
Changed
@@ -81,6 +81,22 @@ */ private ArrayList myArrayList; + /** + * When set to <code>true</code> forward slashes are escaped within the array. + * When set to <code>false</code> no forward slashes are escaped. + * This setting is not inherited to any JSONObject or JSONArray members of the array. + * It is only for simple strings. + * Escaping needs to be set for each contained JSONObject or JSONArray object. + */ + private boolean escapeForwardSlashAlways = true; + + public boolean isEscapeForwardSlashAlways() { + return escapeForwardSlashAlways; + } + + public void setEscapeForwardSlashAlways(boolean escapeForwardSlashAlways) { + this.escapeForwardSlashAlways = escapeForwardSlashAlways; + } /** * Construct an empty JSONArray. @@ -91,6 +107,7 @@ /** * Construct an empty JSONArray with a given capacity. + * @param capacity the initial capacity */ public JSONArray(int capacity) { this.myArrayList = new ArrayList(capacity); @@ -162,24 +179,33 @@ /** * Construct a JSONArray from a Collection. * @param collection A Collection. + * @throws JSONException If there is a syntax error. */ - public JSONArray(Collection collection) { + public JSONArray(Collection collection) throws JSONException { + this(collection, 0); + } + + private JSONArray(Collection collection, int recursionDepth) throws JSONException { + if (recursionDepth > JSONObject.getGlobalRecursionDepthLimit()) { + throw new JSONException("JSONArray has reached recursion depth limit of " + + JSONObject.getGlobalRecursionDepthLimit()); + } + this.myArrayList = (collection == null) ? new ArrayList() : new ArrayList(collection); // ensure a pure hierarchy of JSONObjects and JSONArrays for (ListIterator iter = myArrayList.listIterator(); iter.hasNext();) { - Object e = iter.next(); - if (e instanceof Collection) { - iter.set(new JSONArray((Collection) e)); - } - if (e instanceof Map) { - iter.set(new JSONObject((Map) e)); - } - } + Object e = iter.next(); + if (e instanceof Collection) { + iter.set(new JSONArray((Collection) e, recursionDepth + 1)); + } + if (e instanceof Map) { + iter.set(new JSONObject((Map) e)); + } + } } - /** * Get the object value associated with an index. * @param index @@ -343,7 +369,7 @@ if (i > 0) { sb.append(separator); } - sb.append(JSONObject.valueToString(this.myArrayList.get(i), true)); + sb.append(JSONObject.valueToString(this.myArrayList.get(i), escapeForwardSlashAlways)); } return sb.toString(); } @@ -563,8 +589,9 @@ * JSONArray which is produced from a Collection. * @param value A Collection value. * @return this. + * @throws JSONException If there is a syntax error. */ - public JSONArray put(Collection value) { + public JSONArray put(Collection value) throws JSONException { put(new JSONArray(value)); return this; } @@ -604,7 +631,7 @@ * @return this. */ public JSONArray put(long value) { - put(new Long(value)); + put(Long.valueOf(value)); return this; } @@ -614,8 +641,9 @@ * JSONObject which is produced from a Map. * @param value A Map value. * @return this. + * @throws JSONException If there is a syntax error. */ - public JSONArray put(Map value) { + public JSONArray put(Map value) throws JSONException { put(new JSONObject(value)); return this; } @@ -710,7 +738,7 @@ * @throws JSONException If the index is negative. */ public JSONArray put(int index, long value) throws JSONException { - put(index, new Long(value)); + put(index, Long.valueOf(value)); return this; } @@ -809,7 +837,7 @@ * representation of the object, beginning * with <code></code> <small>(left bracket)</small> and ending * with <code></code> <small>(right bracket)</small>. - * @throws JSONException + * @throws JSONException JSONException */ public String toString(int indentFactor) throws JSONException { return toString(indentFactor, 0); @@ -824,7 +852,7 @@ * @param indent The indention of the top level. * @return a printable, displayable, transmittable * representation of the array. - * @throws JSONException + * @throws JSONException JSONException */ String toString(int indentFactor, int indent) throws JSONException { int len = length(); @@ -835,7 +863,7 @@ StringBuilder sb = new StringBuilder(""); if (len == 1) { sb.append(JSONObject.valueToString(this.myArrayList.get(0), - indentFactor, indent, true)); + indentFactor, indent, escapeForwardSlashAlways)); } else { int newindent = indent + indentFactor; sb.append('\n'); @@ -847,7 +875,7 @@ sb.append(' '); } sb.append(JSONObject.valueToString(this.myArrayList.get(i), - indentFactor, newindent, true)); + indentFactor, newindent, escapeForwardSlashAlways)); } sb.append('\n'); for (i = 0; i < indent; i += 1) { @@ -878,8 +906,9 @@ * <p> * Warning: This method assumes that the data structure is acyclical. * + * @param writer The writer. * @return The writer. - * @throws JSONException + * @throws JSONException JSONException */ public Writer write(Writer writer) throws JSONException { try { @@ -898,7 +927,7 @@ } else if (v instanceof JSONArray) { ((JSONArray)v).write(writer); } else { - writer.write(JSONObject.valueToString(v, true)); + writer.write(JSONObject.valueToString(v, escapeForwardSlashAlways)); } b = true; }
View file
_service:tar_scm:jettison-1.3.7.tar.gz/src/main/java/org/codehaus/jettison/json/JSONException.java -> _service:tar_scm:jettison-1.5.4.tar.gz/src/main/java/org/codehaus/jettison/json/JSONException.java
Changed
@@ -21,7 +21,6 @@ * @version 2 */ public class JSONException extends Exception { - private Throwable cause; private int line = -1; private int column = -1; /** @@ -40,11 +39,6 @@ public JSONException(Throwable t) { super(t.getMessage(), t); - this.cause = t; - } - - public Throwable getCause() { - return this.cause; } public int getColumn() {
View file
_service:tar_scm:jettison-1.3.7.tar.gz/src/main/java/org/codehaus/jettison/json/JSONObject.java -> _service:tar_scm:jettison-1.5.4.tar.gz/src/main/java/org/codehaus/jettison/json/JSONObject.java
Changed
@@ -25,6 +25,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import org.codehaus.jettison.JSONSequenceTooLargeException; @@ -69,7 +70,7 @@ * <code>{ } / \ : , = ; #</code> and if they do not look like numbers * and if they are not the reserved words <code>true</code>, * <code>false</code>, or <code>null</code>.</li> - * <li>Keys can be followed by <code>=</code> or <code>=></code> as well as + * <li>Keys can be followed by <code>=</code> or <code>=></code> as well as * by <code>:</code>.</li> * <li>Values can be followed by <code>;</code> <small>(semicolon)</small> as * well as by <code>,</code> <small>(comma)</small>.</li> @@ -84,6 +85,13 @@ public class JSONObject implements Serializable { /** + * The default recursion depth limit to prevent stack overflow issues on deeply nested structures. + */ + final static int DEFAULT_RECURSION_DEPTH_LIMIT = 500; + + static int RECURSION_DEPTH_LIMIT = DEFAULT_RECURSION_DEPTH_LIMIT; + + /** * JSONObject.NULL is equivalent to the value that JavaScript calls null, * whilst Java's null is equivalent to the value that JavaScript calls * undefined. @@ -91,15 +99,15 @@ private static final class Null { boolean explicitNull; - - public Null() { - + + public Null() { + } - public Null(boolean explicitNull) { + public Null(boolean explicitNull) { this.explicitNull = explicitNull; } - + /** * There is only intended to be a single instance of the NULL object, * so the clone method returns itself. @@ -128,7 +136,7 @@ public String toString() { return isExplicitNull() ? null : "null"; } - + public boolean isExplicitNull() { return explicitNull; } @@ -138,11 +146,13 @@ /** * The hash map where the JSONObject's properties are kept. */ - private LinkedHashMap myHashMap; + private LinkedHashMap<Object,Object> myHashMap; private boolean dropRootElement; private List ignoredElements; private boolean writeNullAsString = true; private boolean escapeForwardSlashAlways = true; + + /** * It is sometimes more convenient and less ambiguous to have a * <code>NULL</code> object than to use Java's <code>null</code> value. @@ -163,10 +173,10 @@ public JSONObject(List ignoredElements) { this(false, ignoredElements, true, true); } - - public JSONObject(boolean dropRootElement, List ignoredElements, boolean writeNullAsString, + + public JSONObject(boolean dropRootElement, List ignoredElements, boolean writeNullAsString, boolean escapeForwardSlash) { - this.myHashMap = new LinkedHashMap(); + this.myHashMap = new LinkedHashMap<Object,Object>(); this.dropRootElement = dropRootElement; this.ignoredElements = ignoredElements; this.writeNullAsString = writeNullAsString; @@ -210,6 +220,8 @@ throw x.syntaxError("A JSONObject text must end with '}'"); case '}': return; + case '{': + throw x.syntaxError("Expected a key"); default: x.back(); key = x.nextValue().toString(); @@ -254,24 +266,33 @@ * Construct a JSONObject from a Map. * @param map A map object that can be used to initialize the contents of * the JSONObject. + * @throws JSONException If there is a syntax error. */ - public JSONObject(Map map) { + public JSONObject(Map map) throws JSONException { + this(map, 0); + } + + private JSONObject(Map map, int recursionDepth) throws JSONException { + + if (recursionDepth > RECURSION_DEPTH_LIMIT) { + throw new JSONException("JSONObject has reached recursion depth limit of " + RECURSION_DEPTH_LIMIT); + } this.myHashMap = (map == null) ? - new LinkedHashMap() : - new LinkedHashMap(map); + new LinkedHashMap<Object,Object>() : + new LinkedHashMap<Object,Object>(map); // ensure a pure hierarchy of JSONObjects and JSONArrays - for (Object k : myHashMap.keySet()) { - Object v = myHashMap.get(k); + for (Entry entry : myHashMap.entrySet()) { + Object v = entry.getValue(); if (v instanceof Collection) { - myHashMap.put(k, new JSONArray((Collection) v)); + myHashMap.put(entry.getKey(), new JSONArray((Collection) v)); } - if (v instanceof Map) { - myHashMap.put(k, new JSONObject((Map) v)); + if (v instanceof Map && v != map) { + myHashMap.put(entry.getKey(), new JSONObject((Map) v, recursionDepth + 1)); } - } + } } - + /** * Construct a JSONObject from an Object, using reflection to find the * public members. The resulting JSONObject's keys will be the strings @@ -347,7 +368,7 @@ * @param key A key string. * @param value An object to be accumulated under the key. * @return this. - * @throws JSONException If the key is null or if the current value + * @throws JSONException If the key is null or if the current value * associated with the key is not a JSONArray. */ public JSONObject append(String key, Object value) @@ -357,7 +378,7 @@ if (o == null) { put(key, new JSONArray().put(value)); } else if (!(o instanceof JSONArray)){ - throw new JSONException("JSONObject" + key + + throw new JSONException("JSONObject" + key + " is not a JSONArray."); } else { ((JSONArray)o).put(value); @@ -448,7 +469,7 @@ private double doGetDouble(String key, Object o) throws JSONException { try { return o instanceof Number ? - ((Number)o).doubleValue() : + ((Number)o).doubleValue() : Double.valueOf((String)o).doubleValue(); } catch (Exception e) { throw new JSONException("JSONObject" + quote(key) + @@ -468,7 +489,7 @@ */ public int getInt(String key) throws JSONException { return doGetInt(key, get(key)); - + } private int doGetInt(String key, Object o) throws JSONException { return o instanceof Number ? ((Number)o).intValue() : (int)getDouble(key); @@ -672,21 +693,21 @@ } } - + /** * Put a key/value pair in the JSONObject, where the value will be a * JSONArray which is produced from a Collection. * @param key A key string. * @param value A Collection value. * @return this. - * @throws JSONException + * @throws JSONException JSONException */ public JSONObject put(String key, Collection value) throws JSONException { put(key, new JSONArray(value)); return this; } -
View file
_service:tar_scm:jettison-1.3.7.tar.gz/src/main/java/org/codehaus/jettison/json/JSONTokener.java -> _service:tar_scm:jettison-1.5.4.tar.gz/src/main/java/org/codehaus/jettison/json/JSONTokener.java
Changed
@@ -15,6 +15,8 @@ */ package org.codehaus.jettison.json; +import java.math.BigDecimal; + /** * A JSONTokener takes a source string and extracts characters and tokens from * it. It is used by the JSONObject and JSONArray constructors to parse @@ -24,6 +26,11 @@ */ public class JSONTokener { + private static final String USE_BIGDECIMAL_JSONTOKENER_KEY = "jettison.json.jsontokener.use_bigdecimal"; + public static final boolean USE_BIGDECIMAL_JSONTOKENER = Boolean.getBoolean( USE_BIGDECIMAL_JSONTOKENER_KEY ); + protected boolean useBigDecimal = USE_BIGDECIMAL_JSONTOKENER; + + /** * The index of the next character. */ @@ -37,7 +44,9 @@ private int threshold = -1; - + + private int recursionDepth; + /** * Construct a JSONTokener from a string. * @@ -47,12 +56,12 @@ this.myIndex = 0; this.mySource = s.trim(); } - + /** * Construct a JSONTokener from a string. * * @param s A source string. - * @param t A source threshold. + * @param threshold A source threshold. */ public JSONTokener(String s, int threshold) { this.myIndex = 0; @@ -162,7 +171,7 @@ /** * Get the next char in the string, skipping whitespace * and comments (slashslash, slashstar, and hash). - * @throws JSONException + * @throws JSONException JSONException * @return A character, or 0 if there are no more characters. */ public char nextClean() throws JSONException { @@ -185,11 +194,13 @@ if (next() == '/') { break; } - back(); } } break; default: + if (!more()) { + throw syntaxError("The JSON text is malformed"); + } back(); return '/'; } @@ -308,7 +319,8 @@ /** - * Get the next value. The value can be a Boolean, Double, Integer, + * Get the next value. The value can be a Boolean, Double/BigDecimal + * (depending on -Djettison.json.jsontokener.use_bigdecimal), Integer, * JSONArray, JSONObject, Long, or String, or the JSONObject.NULL object. * @throws JSONException If syntax error. * @@ -392,13 +404,17 @@ } } try { - return new Integer(s); + return Integer.valueOf(s); } catch (Exception e) { try { - return new Long(s); + return Long.valueOf(s); } catch (Exception f) { try { - return new Double(s); + if (useBigDecimal) { + return new BigDecimal(s); + } else { + return new Double(s); + } } catch (Exception g) { return s; } @@ -409,11 +425,24 @@ } protected JSONObject newJSONObject() throws JSONException { - return new JSONObject(this); + checkRecursionDepth(); + JSONObject object = new JSONObject(this); + recursionDepth--; + return object; } - + protected JSONArray newJSONArray() throws JSONException { - return new JSONArray(this); + checkRecursionDepth(); + JSONArray array = new JSONArray(this); + recursionDepth--; + return array; + } + + private void checkRecursionDepth() throws JSONException { + recursionDepth++; + if (recursionDepth > JSONObject.RECURSION_DEPTH_LIMIT) { + throw new JSONException("JSONTokener has reached recursion depth limit of " + JSONObject.RECURSION_DEPTH_LIMIT); + } } /**
View file
_service:tar_scm:jettison-1.3.7.tar.gz/src/main/java/org/codehaus/jettison/json/JSONWriter.java -> _service:tar_scm:jettison-1.5.4.tar.gz/src/main/java/org/codehaus/jettison/json/JSONWriter.java
Changed
@@ -92,13 +92,14 @@ */ private int top; - /**kue + /** * The writer that will receive the output. */ protected Writer writer; /** * Make a fresh JSONWriter. It can be used to build one JSON text. + * @param w writer */ public JSONWriter(Writer w) { this.comma = false; @@ -139,7 +140,7 @@ /** * Begin appending a new array. All values until the balancing * <code>endArray</code> will be appended to this array. The - * <code>endArray</code> method must be called to mark the array's end.kue + * <code>endArray</code> method must be called to mark the array's end. * @return this * @throws JSONException If the nesting is too deep, or if the object is * started in the wrong place (for example as a key or after the end of the @@ -284,7 +285,7 @@ * <code>false</code>. * @param b A boolean. * @return this - * @throws JSONException + * @throws JSONException JSONException */ public JSONWriter value(boolean b) throws JSONException { return this.append(b ? "true" : "false"); @@ -304,7 +305,7 @@ * Append a long value. * @param l A long. * @return this - * @throws JSONExceptionkue + * @throws JSONException JSONException */ public JSONWriter value(long l) throws JSONException { return this.append(Long.toString(l));
View file
_service:tar_scm:jettison-1.3.7.tar.gz/src/main/java/org/codehaus/jettison/mapped/Configuration.java -> _service:tar_scm:jettison-1.5.4.tar.gz/src/main/java/org/codehaus/jettison/mapped/Configuration.java
Changed
@@ -75,6 +75,7 @@ private String attributeKey = "@"; private boolean ignoreNamespaces; private boolean dropRootElement; + private boolean rootElementArrayWrapper = true; private Set primitiveArrayKeys = Collections.EMPTY_SET; private boolean writeNullAsString = true; private boolean readNullAsString; @@ -169,7 +170,14 @@ public void setDropRootElement(boolean dropRootElement) { this.dropRootElement = dropRootElement; } + public boolean isRootElementArrayWrapper() { + return rootElementArrayWrapper; + } + public void setRootElementArrayWrapper(boolean rootElementArrayWrapper) { + this.rootElementArrayWrapper = rootElementArrayWrapper; + } + public boolean isWriteNullAsString() { return writeNullAsString; }
View file
_service:tar_scm:jettison-1.3.7.tar.gz/src/main/java/org/codehaus/jettison/mapped/DefaultConverter.java -> _service:tar_scm:jettison-1.5.4.tar.gz/src/main/java/org/codehaus/jettison/mapped/DefaultConverter.java
Changed
@@ -33,35 +33,194 @@ public Object convertToJSONPrimitive(String text) { if(text == null) return text; - Object primitive = null; - // Attempt to convert to Integer - try { - primitive = enforce32BitInt ? Integer.valueOf(text) : Long.valueOf(text); - } catch (Exception e) {/**/} - // Attempt to convert to double - if (primitive == null) { - try { - Double v = Double.valueOf(text); - if( !v.isInfinite() && !v.isNaN() ) { - primitive = v; + + // If there's at least one character + if (text.length() >= 1) { + // find the first character + char first = text.charAt(0); + + // Is it incompatible with a number? + if ((first < '0' || first > '9') && first != '-') { + // Yes it is, so special case check for Boolean values + if (first == 't') { + if (text.equals("true")) { + return Boolean.TRUE; + } + } else if (first == 'f') { + if (text.equals("false")) { + return Boolean.FALSE; + } } - else { + + // Definitely not a Boolean or a number, so return the original value + return text; + } + } + + Object primitive = null; + + if (enforce32BitInt) { + primitive = getInteger(text); + } else { + primitive = getLong(text); + } + + if (primitive == null) { + Double dbl = getDouble(text); + + if (dbl != null) { + if (dbl.isInfinite() || dbl.isNaN()) { primitive = text; } - } catch (Exception e) {/**/} - } - // Attempt to convert to boolean - if (primitive == null) { - if(text.trim().equalsIgnoreCase("true") || text.trim().equalsIgnoreCase("false")) { - primitive = Boolean.valueOf(text); - } - } - - if (primitive == null || !primitive.toString().equals(text)) { - // Default String - primitive = text; - } - - return primitive; + else { + primitive = dbl; + } + } + } + + if (primitive == null || !primitive.toString().equals(text)) { + // Default String + primitive = text; + } + + return primitive; + } + + private static final int MAX_LENGTH_LONG = String.valueOf(Long.MAX_VALUE).length(); + private static final int MAX_LENGTH_LONG_NEGATIVE = String.valueOf(Long.MAX_VALUE).length() + 1; + + /** + * Try to get a Long value efficiently, avoiding Exceptions + */ + private static Long getLong(String text) + { + // handle an empty string + if (text.isEmpty()) return null; + + // if the text is too long it can't be a Long + if (text.charAt(0) == '-') { + if (text.length() > MAX_LENGTH_LONG_NEGATIVE) { + return null; + } + } else if (text.length() > MAX_LENGTH_LONG) { + return null; + } + + // Handle a leading minus sign + int i = 0; + if (text.charAt(0) == '-') { + if (text.length() > 1) { + i++; + } else { + return null; + } + } + + // Check each character is a digit + for (; i < text.length(); i++) { + if (!Character.isDigit(text.charAt(i))) { + return null; + } + } + + // It looks like it might be a Long, so give it a go + try { + return Long.parseLong(text); + } catch (Exception e) { + // It isn't a Long + return null; + } + } + + private static final int MAX_LENGTH_INTEGER = String.valueOf(Integer.MAX_VALUE).length(); + private static final int MAX_LENGTH_INTEGER_NEGATIVE = String.valueOf(Integer.MAX_VALUE).length() + 1; + + /** + * Try to get an Integer value efficiently, avoiding Exceptions + */ + private static Integer getInteger(String text) { + // handle an empty string + if (text.isEmpty()) return null; + + // if the text is too long it can't be an Integer + if (text.charAt(0) == '-') { + if (text.length() > MAX_LENGTH_INTEGER_NEGATIVE) { + return null; + } + } + else if (text.length() > MAX_LENGTH_INTEGER) { + return null; + } + + // Handle a leading minus sign + int i = 0; + if (text.charAt(0) == '-') { + if (text.length() > 1) { + i++; + } else { + return null; + } + } + + // Check each character is a digit + for (; i < text.length(); i++) { + if (!Character.isDigit(text.charAt(i))) { + return null; + } + } + + // It looks like it might be an Integer, so give it a go + try { + return Integer.parseInt(text); + } catch (Exception e) { + // It isn't an Integer + return null; + } + } + + /** + * Try to get a Double value efficiently, avoiding Exceptions + */ + private static Double getDouble(String text) { + boolean foundDP = false; + boolean foundExp = false; + + // handle an empty string + if (text.isEmpty()) + return null; + + // Handle a leading minus sign + int i = 0; + if (text.charAt(0) == '-') { + if (text.length() > 1) + i++; + else + return null; + } + + // Check each character is a digit + for (; i < text.length(); i++) { + char next = text.charAt(i); + if (!Character.isDigit(next)) {
View file
_service:tar_scm:jettison-1.3.7.tar.gz/src/main/java/org/codehaus/jettison/mapped/MappedNamespaceConvention.java -> _service:tar_scm:jettison-1.5.4.tar.gz/src/main/java/org/codehaus/jettison/mapped/MappedNamespaceConvention.java
Changed
@@ -40,7 +40,7 @@ public class MappedNamespaceConvention implements Convention, NamespaceContext { private static final String DOT_NAMESPACE_SEP = "."; private Map<Object, Object> xnsToJns = new HashMap<Object, Object>(); - private Map<Object, Object> jnsToXns = new HashMap<Object, Object>(); + private Map<String, Object> jnsToXns = new HashMap<String, Object>(); private List<?> attributesAsElements; private List<?> ignoredElements; private List<String> jsonAttributesAsElements; @@ -51,6 +51,7 @@ private Set<?> primitiveArrayKeys; private boolean dropRootElement; private boolean writeNullAsString = true; + private boolean rootElementArrayWrapper = true; private boolean ignoreEmptyArrayValues; private boolean readNullAsString; private boolean escapeForwardSlashAlways; @@ -66,6 +67,7 @@ this.supressAtAttributes = config.isSupressAtAttributes(); this.ignoreNamespaces = config.isIgnoreNamespaces(); this.dropRootElement = config.isDropRootElement(); + this.rootElementArrayWrapper = config.isRootElementArrayWrapper(); this.attributeKey = config.getAttributeKey(); this.primitiveArrayKeys = config.getPrimitiveArrayKeys(); this.ignoredElements = config.getIgnoredElements(); @@ -74,7 +76,7 @@ this.jsonNamespaceSeparator = config.getJsonNamespaceSeparator(); for (Iterator<Map.Entry<Object, Object>> itr = xnsToJns.entrySet().iterator(); itr.hasNext();) { Map.Entry<?, ?> entry = itr.next(); - jnsToXns.put(entry.getValue(), entry.getKey()); + jnsToXns.put((String)entry.getValue(), entry.getKey()); } jsonAttributesAsElements = new ArrayList<String>(); @@ -135,6 +137,25 @@ n.setNamespace( prefix, uri ); } } + // With the 1.0 release, the default behavior was to treat an @xmlns + // JSON field name (without a namespace prefix), as the attribute for + // the default namespace URI. During JSON->XML serialization, this + // default behavior resulted in an xmlns (without a namespace prefix) + // attribute appearing on the applicable element, with the default + // namespace uri as it's value. + // + // The code refactoring in this processAttributesAndNamespaces + // method back in the 2.0 release, no longer assigns the default + // namespace URI to the xmlns (without a namespace prefix) during JSON->XML + // serialization, which in some cases is causing unmarshaling issues. + // Putting in the following conditional check, restores the previous + // default behavior, without breaking anything added during the earlier + // refactoring exercise. + if (o instanceof String) { + String uri = o.toString(); + QName name = new QName( XMLConstants.DEFAULT_NS_PREFIX, k); + n.setAttribute(name, uri); + } } else { String strValue = o == null ? null : o.toString(); @@ -191,10 +212,10 @@ } } - public Iterator<Object> getPrefixes( String arg0 ) { + public Iterator<String> getPrefixes( String arg0 ) { if ( ignoreNamespaces ) { - return Collections.emptySet().iterator(); + return Collections.<String>emptySet().iterator(); } else { return jnsToXns.keySet().iterator(); @@ -313,10 +334,13 @@ public boolean isDropRootElement() { return dropRootElement; } + public boolean isRootElementArrayWrapper() { + return rootElementArrayWrapper; + } public List<?> getIgnoredElements() { - return ignoredElements; - } - public boolean isWriteNullAsString() { + return ignoredElements; + } + public boolean isWriteNullAsString() { return writeNullAsString; } public boolean isReadNullAsString() {
View file
_service:tar_scm:jettison-1.3.7.tar.gz/src/main/java/org/codehaus/jettison/mapped/MappedXMLStreamReader.java -> _service:tar_scm:jettison-1.5.4.tar.gz/src/main/java/org/codehaus/jettison/mapped/MappedXMLStreamReader.java
Changed
@@ -50,7 +50,11 @@ if (top instanceof JSONObject) { this.node = new Node(null, rootName, (JSONObject)top, convention); } else if (top instanceof JSONArray && !(((JSONArray)top).length() == 1 && ((JSONArray)top).get(0).equals(""))) { - this.node = new Node(null, rootName, obj, convention); + if (con.isRootElementArrayWrapper()) { + this.node = new Node(null, rootName, obj, convention); + } else { + this.node = new Node(null, rootName, ((JSONArray)top).getJSONObject(0), convention); + } } else { node = new Node(rootName, convention); convention.processAttributesAndNamespaces(node, obj);
View file
_service:tar_scm:jettison-1.3.7.tar.gz/src/main/java/org/codehaus/jettison/mapped/MappedXMLStreamWriter.java -> _service:tar_scm:jettison-1.5.4.tar.gz/src/main/java/org/codehaus/jettison/mapped/MappedXMLStreamWriter.java
Changed
@@ -109,7 +109,7 @@ Object value = property.getValue(); boolean emptyString = value instanceof String && ((String)value).isEmpty(); - if (add && value instanceof String && !emptyString) { + if (value instanceof String && !emptyString) { value = convention.convertToJSONPrimitive((String)value); } if (getSerializedAsArrays().contains(getPropertyArrayKey(property))) { @@ -165,7 +165,7 @@ } public JSONPropertyObject withProperty(JSONProperty property, boolean add) { Object value = property.getValue(); - if(add && value instanceof String) { + if(value instanceof String && !((String)value).isEmpty()) { value = convention.convertToJSONPrimitive((String)value); } Object old = object.opt(property.getKey()); @@ -243,6 +243,10 @@ } public void writeStartElement(String prefix, String local, String ns) throws XMLStreamException { + if (current == null) { + this.writeStartDocument(); + } + String parentKey = current.getTreeKey(); stack.push(current); String key = convention.createKey(prefix, ns, local); @@ -288,6 +292,8 @@ /** * For clients who want to modify the output object before writing to override. + * @param root root + * @throws XMLStreamException XMLStreamException */ protected void writeJSONObject(JSONObject root) throws XMLStreamException { try {
View file
_service:tar_scm:jettison-1.3.7.tar.gz/src/main/java/org/codehaus/jettison/util/StringIndenter.java -> _service:tar_scm:jettison-1.5.4.tar.gz/src/main/java/org/codehaus/jettison/util/StringIndenter.java
Changed
@@ -78,7 +78,7 @@ return null; } String resultString = this.result.toString(); - return resultString == null ? null : resultString.trim(); + return resultString.trim(); } /**
View file
_service:tar_scm:jettison-1.3.7.tar.gz/src/test/java/org/codehaus/jettison/badgerfish/BadgerFishDOMTest.java -> _service:tar_scm:jettison-1.5.4.tar.gz/src/test/java/org/codehaus/jettison/badgerfish/BadgerFishDOMTest.java
Changed
@@ -94,7 +94,7 @@ String resStr = toJSON(parse(xmlStr)); assertEquals("Unexpected result: " + resStr, expStr, resStr); - String resXML = toXML(resStr).replace(System.getProperty("line.separator"), ""); + String resXML = toXML(resStr).replace(System.getProperty("line.separator"), "").replaceAll(">\\s+<", "><"); assertEquals("Unexpected result: " + resXML, xmlStr, resXML); } @@ -104,7 +104,7 @@ String resStr = toJSON(parse(xmlStr)); assertEquals("Unexpected result: " + resStr, expStr, resStr); - String resXML = toXML(resStr).replace(System.getProperty("line.separator"), ""); + String resXML = toXML(resStr).replace(System.getProperty("line.separator"), "").replaceAll(">\\s+<", "><"); assertEquals("Unexpected result: " + resXML, xmlStr, resXML); }
View file
_service:tar_scm:jettison-1.3.7.tar.gz/src/test/java/org/codehaus/jettison/json/JSONArrayTest.java -> _service:tar_scm:jettison-1.5.4.tar.gz/src/test/java/org/codehaus/jettison/json/JSONArrayTest.java
Changed
@@ -2,6 +2,9 @@ import junit.framework.TestCase; +import java.util.ArrayList; +import java.util.List; + public class JSONArrayTest extends TestCase { public void testInvalidArraySequence() throws Exception { try { @@ -20,4 +23,65 @@ assertTrue(ex.getMessage().startsWith("Expected a ',' or ''")); } } + + public void testEscapingInArrayIsOnByDefault() { + JSONArray array = new JSONArray(); + array.put("a string with / character"); + String expectedValue = "\"a string with \\/ character\""; + assertEquals(expectedValue, array.toString()); + } + + public void testEscapingInArrayIsTrunedOff() throws JSONException { + + JSONObject obj = new JSONObject(); + obj.put("key", "http://example.com/foo"); + obj.setEscapeForwardSlashAlways(false); + + JSONArray array = new JSONArray(); + array.put("a string with / character"); + array.put(obj); + array.setEscapeForwardSlashAlways(false); + + System.out.println(array.toString()); + String expectedValue = "\"a string with / character\",{\"key\":\"http://example.com/foo\"}"; + assertEquals(expectedValue, array.toString()); + } + + public void testInfiniteLoop() { + String str = "*/*A25 **"; + try { + new JSONArray(str); + fail("Failure expected on malformed JSON"); + } catch (JSONException ex) { + // expected + } + } + + public void testInfiniteLoop2() { + String str = "/"; + try { + new JSONArray(str); + fail("Failure expected on malformed JSON"); + } catch (JSONException ex) { + // expected + } + } + + public void testIssue52() throws JSONException { + JSONObject.setGlobalRecursionDepthLimit(10); + new JSONArray("{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {a:10}"); + JSONObject.setGlobalRecursionDepthLimit(500); + } + + // https://github.com/jettison-json/jettison/issues/60 + public void testIssue60() throws JSONException { + List<Object> list = new ArrayList<>(); + list.add(list); + try { + new JSONArray(list); + } catch (JSONException ex) { + assertEquals(ex.getMessage(), "JSONArray has reached recursion depth limit of 500"); + } + } + }
View file
_service:tar_scm:jettison-1.3.7.tar.gz/src/test/java/org/codehaus/jettison/json/JSONObjectTest.java -> _service:tar_scm:jettison-1.5.4.tar.gz/src/test/java/org/codehaus/jettison/json/JSONObjectTest.java
Changed
@@ -2,7 +2,13 @@ import junit.framework.TestCase; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + public class JSONObjectTest extends TestCase { + public void testEquals() throws Exception { JSONObject aJsonObj = new JSONObject("{\"x\":\"y\"}"); JSONObject bJsonObj = new JSONObject("{\"x\":\"y\"}"); @@ -77,4 +83,132 @@ JSONObject obj = new JSONObject("{\"a\":null}"); assertTrue(obj.isNull("b")); } + + public void testSlashEscapingTurnedOnByDefault() throws Exception { + JSONObject obj = new JSONObject(); + obj.put("key", "http://example.com/foo"); + assertEquals("{\"key\":\"http:\\/\\/example.com\\/foo\"}", obj.toString()); + + obj = new JSONObject(); + obj.put("key", "\\\\"); + assertEquals("{\"key\":\"\\\\\\\\\"}", obj.toString()); + } + + public void testForwardSlashEscapingModifiedfBySetter() throws Exception { + JSONObject obj = new JSONObject(); + obj.put("key", "http://example.com/foo"); + assertEquals(obj.toString(), "{\"key\":\"http:\\/\\/example.com\\/foo\"}"); + obj.setEscapeForwardSlashAlways(false); + assertEquals(obj.toString(), "{\"key\":\"http://example.com/foo\"}"); + obj.setEscapeForwardSlashAlways(true); + assertEquals(obj.toString(), "{\"key\":\"http:\\/\\/example.com\\/foo\"}"); + } + + public void testMalformedObject() throws Exception { + try { + new JSONObject("{/"); + fail("Failure expected on malformed JSON"); + } catch (JSONException ex) { + // expected + } + } + + public void testMalformedObject2() throws Exception { + try { + new JSONObject("{x"); + fail("Failure expected on malformed JSON"); + } catch (JSONException ex) { + // expected + } + } + + public void testMalformedObject3() throws Exception { + try { + new JSONObject("{/x"); + fail("Failure expected on malformed JSON"); + } catch (JSONException ex) { + // expected + } + } + + public void testMalformedObject4() throws Exception { + try { + new JSONObject("{/*"); + fail("Failure expected on malformed JSON"); + } catch (JSONException ex) { + // expected + } + } + + public void testMalformedObject5() throws Exception { + try { + new JSONObject("{//"); + fail("Failure expected on malformed JSON"); + } catch (JSONException ex) { + // expected + } + } + + public void testMalformedArray() throws Exception { + try { + new JSONObject("{/"); + fail("Failure expected on malformed JSON"); + } catch (JSONException ex) { + // expected + } + } + + // https://github.com/jettison-json/jettison/issues/52 + public void testIssue52() throws Exception { + Map<String,Object> map = new HashMap<>(); + map.put("t",map); + new JSONObject(map); + } + + // https://github.com/jettison-json/jettison/issues/52 + public void testIssue52Recursive() throws Exception { + try { + Map<String, Object> map = new HashMap<>(); + Map<String, Object> map2 = new HashMap<>(); + map.put("t", map2); + map2.put("t", map); + new JSONObject(map); + fail("Failure expected"); + } catch (JSONException e) { + assertTrue(e.getMessage().contains("JSONObject has reached recursion depth limit")); + // expected + } + } + + // https://github.com/jettison-json/jettison/issues/45 + public void testFuzzerTestCase() throws Exception, JSONException { + try { + new JSONObject("{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{\"G\":30018084,1,6,32768,1,1,6,1,1}:3,1,6,32768,1,1,6,1,1}:3,1,6,32768,1,1,6,1,1}:3,1,6,32768,1,1,6,1,1}:3,1,6,32768,1,1,6,1,1}:3,1,6,32768,1,1,6,1,1}:3,1,6,32768,1,1,6,1,1}:3,1,6,38,1,1,6,1,1}:3,1,6,32768,1,1,6,1,1}:3,1,6,32768,1,1,6,1,1}:3,1,6,32768,1,1,6,1,1}:3,1,6,32768,1,1,6,1,1}:3,1,6,32768,1,1,6,1,1}:3,1,6,32768,1,1,6,1,0}:3,1,6,32768,1,1,6,1,1}:3,1,6,32768,1,340282366920938463463374607431768211458,6,1,1}:32768,1,1,6,1,0}:3,1,6,32768,1,1,6,1,1}:3,1,6,32768,1,340282366920938463463374607431768211458,6,1,1}:3,1,6,32768,1,1,6,1,1}:3,1,6,32768,9 68,1,127,1,1}:3,1,6,32768,1,1,6,1,1}:3,1,6,32768,1,1,6,1,1}:3,1,6,32768,1,1,6,1,1}:3,1,6,32768,1,1,6,1,1}:3,1,6,32768,1,1,6,1,1}:3,1,6,32768,1,1,6,1,9223372036854775807}:3,1,6,32768,1,1,6,1,1}:3,1,10,32768,1,1,6,1,1}"); + fail("Failure expected"); + } catch (JSONException ex) { + // expected + assertTrue(ex.getMessage().contains("Expected a key")); + } + } + + public void testFuzzerTestCase2() throws Exception { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < 100000; i++) { + sb.append("{\"key\":"); + } + try { + new JSONObject(sb.toString()); + fail("Failure expected"); + } catch (JSONException e) { + assertTrue(e.getMessage().contains("JSONTokener has reached recursion depth limit")); + // expected + } + } + + public void testIssue58() throws JSONException { + Map<String, Object> map = new HashMap<>(); + map.put("request", "{\"exclude\":\".\",\"?\",\"+\",\"*\",\"|\",\"{\",\"}\",\"\",\"\",\"(\",\")\",\"\\\"\",\"\\\\\",\"#\",\"@\",\"&\",\"<\",\">\",\"~\"}"); + JSONObject jsonObject = new JSONObject(map); + JSONObject jsonObject1 = new JSONObject(jsonObject.toString()); + } }
View file
_service:tar_scm:jettison-1.5.4.tar.gz/src/test/java/org/codehaus/jettison/json/JSONTokenerTest.java
Added
@@ -0,0 +1,27 @@ +package org.codehaus.jettison.json; + +import java.math.BigDecimal; + +import junit.framework.TestCase; + +public class JSONTokenerTest extends TestCase { + + public void testDoublePrecision() throws Exception { + JSONTokener doubleTokener = new JSONTokener("9999999999999.9999"); + Object nextValue = doubleTokener.nextValue(); + assertEquals(Double.class, nextValue.getClass()); + assertEquals(Double.valueOf("1.0E13"), nextValue); + } + + public void testBigDecimalPrecision() throws Exception { + JSONTokener bigDecimalTokener = new JSONTokener("9999999999999.9999") { + { + this.useBigDecimal = true; + } + }; + Object nextValue = bigDecimalTokener.nextValue(); + assertEquals(BigDecimal.class, nextValue.getClass()); + assertEquals(new BigDecimal("9999999999999.9999"), nextValue); + } + +}
View file
_service:tar_scm:jettison-1.3.7.tar.gz/src/test/java/org/codehaus/jettison/mapped/MappedDOMTest.java -> _service:tar_scm:jettison-1.5.4.tar.gz/src/test/java/org/codehaus/jettison/mapped/MappedDOMTest.java
Changed
@@ -70,7 +70,7 @@ public void testIgnoreNamespaces() throws Exception { String xmlStr = "<A xmlns=\"http://foo\"><B xmlns:bar=\"http://baz\" bar:c=\"1\">2</B></A>"; - String expStr = "{\"A\":{\"B\":{\"@c\":\"1\",\"$\":\"2\"}}}"; + String expStr = "{\"A\":{\"B\":{\"@c\":1,\"$\":\"2\"}}}"; String resStr = toJSON(parse(xmlStr), true); assertEquals("Unexpected result: " + resStr, expStr, resStr); resStr="{\"somens.kermit\":\"the frog\"}";
View file
_service:tar_scm:jettison-1.3.7.tar.gz/src/test/java/org/codehaus/jettison/mapped/MappedXMLStreamWriterTest.java -> _service:tar_scm:jettison-1.5.4.tar.gz/src/test/java/org/codehaus/jettison/mapped/MappedXMLStreamWriterTest.java
Changed
@@ -25,10 +25,10 @@ import javax.xml.namespace.QName; import javax.xml.stream.XMLStreamException; -import junit.framework.TestCase; - import org.codehaus.jettison.AbstractXMLStreamWriter; +import junit.framework.TestCase; + public class MappedXMLStreamWriterTest extends TestCase { public void testRoot() throws Exception { @@ -318,6 +318,44 @@ assertEquals("{\"root\":{\"@att\":\"attvalue\",\"@foo.att2\":\"attvalue\"}}", strWriter.toString()); } + + public void testIntAttribute() throws Exception { + StringWriter strWriter = new StringWriter(); + + MappedNamespaceConvention con = new MappedNamespaceConvention(new Configuration()); + AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter); + + w.writeStartDocument(); + w.writeStartElement("root"); + w.writeAttribute("att", "123"); + w.writeEndElement(); + w.writeEndDocument(); + + w.close(); + strWriter.close(); + + assertEquals("{\"root\":{\"@att\":123}}", strWriter.toString()); + } + public void testIntAttributeAsString() throws Exception { + StringWriter strWriter = new StringWriter(); + + Configuration c = new Configuration(); + c.setTypeConverter(new SimpleConverter()); + MappedNamespaceConvention con = new MappedNamespaceConvention(c); + AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter); + + w.writeStartDocument(); + w.writeStartElement("root"); + w.writeAttribute("att", "123"); + w.writeEndElement(); + w.writeEndDocument(); + + w.close(); + strWriter.close(); + + assertEquals("{\"root\":{\"@att\":\"123\"}}", strWriter.toString()); + } + public void testAttributesAsElements() throws Exception { StringWriter strWriter = new StringWriter(); @@ -1218,7 +1256,7 @@ "{\"@name\":\"reason\"},{\"@name\":\"terms\"},\"numeric\":" + "{\"@name\":\"amountasked\"},{\"@name\":\"amountoffered\"}," + "\"structure\":{\"@name\":\"check\",\"symbolic\":" + - "{\"@name\":\"date\"},\"structure\":{\"@name\":\"lines\",\"@repeating\":\"true\",\"symbolic\"" + + "{\"@name\":\"date\"},\"structure\":{\"@name\":\"lines\",\"@repeating\":true,\"symbolic\"" + ":{\"@name\":\"type\"},\"numeric\":{\"@name\":\"amount\"},{\"@name\":\"cost\"}}}}}}" , strWriter.toString()); }
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2