Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: kriszyp/json-schema
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 07ae2c618b5f581dbc108e065f4f95dcf0a1d85f
Choose a base ref
...
head repository: kriszyp/json-schema
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f6f6a3b02d667aa4ba2d5d50cc19208c4462abfa
Choose a head ref

Commits on Dec 12, 2013

  1. Error message updated. Added value to log output.

    Darshan Mehta committed Dec 12, 2013
    Copy the full SHA
    ab35100 View commit details

Commits on Dec 10, 2015

  1. Add license text

    This is one of the requirements of the BSD license:
      * Redistributions of source code must retain the above copyright
        notice, this list of conditions and the following disclaimer.
    piotr1212 committed Dec 10, 2015
    Copy the full SHA
    ee0c11c View commit details

Commits on Feb 29, 2016

  1. Copy the full SHA
    9fedde5 View commit details

Commits on Oct 26, 2016

  1. Copy the full SHA
    81ca359 View commit details

Commits on Oct 27, 2016

  1. Merge pull request #72 from CDanU/master

    specifies license type (BSD -> BSD 3-Clause)
    kriszyp authored Oct 27, 2016
    Copy the full SHA
    24c4ed1 View commit details

Commits on Dec 1, 2017

  1. Updating deprecated licenses field

    "licenses" field is deprecated in favor of a "license" field with an SPDX expression (see https://docs.npmjs.com/files/package.json#license)
    camillem authored Dec 1, 2017
    Copy the full SHA
    3ccbf04 View commit details

Commits on Mar 20, 2018

  1. Merge pull request #77 from camillem/patch-1

    Updating deprecated licenses field
    kriszyp authored Mar 20, 2018
    Copy the full SHA
    2cd9889 View commit details

Commits on Jul 19, 2018

  1. Merge pull request #61 from piotr1212/master

    Add license text
    kriszyp authored Jul 19, 2018
    Copy the full SHA
    eef3d20 View commit details
  2. Copy the full SHA
    4f3db68 View commit details

Commits on Oct 31, 2018

  1. Defined files property

    paazmaya committed Oct 31, 2018
    Copy the full SHA
    f31090b View commit details

Commits on Sep 6, 2019

  1. Merge pull request #80 from paazmaya/79-add-files-property

    Defined files property
    kriszyp authored Sep 6, 2019
    Copy the full SHA
    27848fc View commit details
  2. Merge pull request #78 from mvandervliet/spdx_license_text

    Updated LICENSE text to use SPDX license identifiers where applicable
    kriszyp authored Sep 6, 2019
    Copy the full SHA
    f4cf71d View commit details
  3. Merge pull request #70 from damehta/master

    Error message updated. Added value to log output.
    kriszyp authored Sep 6, 2019
    Copy the full SHA
    431200e View commit details
  4. Merge pull request #66 from technical-team/additional-props-message

    Clean up error message for additionalProperties: false
    kriszyp authored Sep 6, 2019
    Copy the full SHA
    6b8b8ca View commit details
  5. Copy the full SHA
    55a6a1b View commit details
  6. Update version

    kriszyp committed Sep 6, 2019
    Copy the full SHA
    1e4c8aa View commit details

Commits on Sep 19, 2020

  1. Remove typeof comparing to undefined

    This comparison is invalid, because typeof always returns strings.
    hodovani authored Sep 19, 2020
    Copy the full SHA
    ae602f0 View commit details
  2. Merge pull request #81 from hodovani/patch-1

    Remove typeof comparing to undefined
    kriszyp authored Sep 19, 2020
    Copy the full SHA
    7dff9cd View commit details

Commits on Sep 29, 2020

  1. Copy the full SHA
    c28470f View commit details
  2. Update version

    kriszyp committed Sep 29, 2020
    Copy the full SHA
    3b0cec3 View commit details

Commits on Oct 3, 2021

  1. Add security policy

    kriszyp committed Oct 3, 2021
    Copy the full SHA
    b3f42b3 View commit details

Commits on Oct 9, 2021

  1. Get basic test to pass

    kriszyp committed Oct 9, 2021
    Copy the full SHA
    c52a27c View commit details
  2. Copy the full SHA
    22f1461 View commit details
  3. Copy the full SHA
    fb427cd View commit details

Commits on Nov 2, 2021

  1. Copy the full SHA
    b62f1da View commit details
  2. Update version

    kriszyp committed Nov 2, 2021
    Copy the full SHA
    ef60987 View commit details
  3. 5
    Copy the full SHA
    f6f6a3b View commit details
Showing with 260 additions and 37 deletions.
  1. +3 −0 .gitignore
  2. +195 −0 LICENSE
  3. +2 −4 README.md
  4. +11 −0 SECURITY.md
  5. +1 −2 lib/links.js
  6. +7 −9 lib/validate.js
  7. +5 −12 package.json
  8. +36 −10 test/tests.js
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
yarn.lock
.vscode
195 changes: 195 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
Dojo is available under *either* the terms of the BSD 3-Clause "New" License *or* the
Academic Free License version 2.1. As a recipient of Dojo, you may choose which
license to receive this code under (except as noted in per-module LICENSE
files). Some modules may not be the copyright of the Dojo Foundation. These
modules contain explicit declarations of copyright in both the LICENSE files in
the directories in which they reside and in the code itself. No external
contributions are allowed under licenses which are fundamentally incompatible
with the AFL-2.1 OR and BSD-3-Clause licenses that Dojo is distributed under.

The text of the AFL-2.1 and BSD-3-Clause licenses is reproduced below.

-------------------------------------------------------------------------------
BSD 3-Clause "New" License:
**********************

Copyright (c) 2005-2015, The Dojo Foundation
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 Dojo Foundation 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 OWNER 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.

-------------------------------------------------------------------------------
The Academic Free License, v. 2.1:
**********************************

This Academic Free License (the "License") applies to any original work of
authorship (the "Original Work") whose owner (the "Licensor") has placed the
following notice immediately following the copyright notice for the Original
Work:

Licensed under the Academic Free License version 2.1

1) Grant of Copyright License. Licensor hereby grants You a world-wide,
royalty-free, non-exclusive, perpetual, sublicenseable license to do the
following:

a) to reproduce the Original Work in copies;

b) to prepare derivative works ("Derivative Works") based upon the Original
Work;

c) to distribute copies of the Original Work and Derivative Works to the
public;

d) to perform the Original Work publicly; and

e) to display the Original Work publicly.

2) Grant of Patent License. Licensor hereby grants You a world-wide,
royalty-free, non-exclusive, perpetual, sublicenseable license, under patent
claims owned or controlled by the Licensor that are embodied in the Original
Work as furnished by the Licensor, to make, use, sell and offer for sale the
Original Work and Derivative Works.

3) Grant of Source Code License. The term "Source Code" means the preferred
form of the Original Work for making modifications to it and all available
documentation describing how to modify the Original Work. Licensor hereby
agrees to provide a machine-readable copy of the Source Code of the Original
Work along with each copy of the Original Work that Licensor distributes.
Licensor reserves the right to satisfy this obligation by placing a
machine-readable copy of the Source Code in an information repository
reasonably calculated to permit inexpensive and convenient access by You for as
long as Licensor continues to distribute the Original Work, and by publishing
the address of that information repository in a notice immediately following
the copyright notice that applies to the Original Work.

4) Exclusions From License Grant. Neither the names of Licensor, nor the names
of any contributors to the Original Work, nor any of their trademarks or
service marks, may be used to endorse or promote products derived from this
Original Work without express prior written permission of the Licensor. Nothing
in this License shall be deemed to grant any rights to trademarks, copyrights,
patents, trade secrets or any other intellectual property of Licensor except as
expressly stated herein. No patent license is granted to make, use, sell or
offer to sell embodiments of any patent claims other than the licensed claims
defined in Section 2. No right is granted to the trademarks of Licensor even if
such marks are included in the Original Work. Nothing in this License shall be
interpreted to prohibit Licensor from licensing under different terms from this
License any Original Work that Licensor otherwise would have a right to
license.

5) This section intentionally omitted.

6) Attribution Rights. You must retain, in the Source Code of any Derivative
Works that You create, all copyright, patent or trademark notices from the
Source Code of the Original Work, as well as any notices of licensing and any
descriptive text identified therein as an "Attribution Notice." You must cause
the Source Code for any Derivative Works that You create to carry a prominent
Attribution Notice reasonably calculated to inform recipients that You have
modified the Original Work.

7) Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that
the copyright in and to the Original Work and the patent rights granted herein
by Licensor are owned by the Licensor or are sublicensed to You under the terms
of this License with the permission of the contributor(s) of those copyrights
and patent rights. Except as expressly stated in the immediately proceeding
sentence, the Original Work is provided under this License on an "AS IS" BASIS
and WITHOUT WARRANTY, either express or implied, including, without limitation,
the warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU.
This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No
license to Original Work is granted hereunder except under this disclaimer.

8) Limitation of Liability. Under no circumstances and under no legal theory,
whether in tort (including negligence), contract, or otherwise, shall the
Licensor be liable to any person for any direct, indirect, special, incidental,
or consequential damages of any character arising as a result of this License
or the use of the Original Work including, without limitation, damages for loss
of goodwill, work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses. This limitation of liability shall not
apply to liability for death or personal injury resulting from Licensor's
negligence to the extent applicable law prohibits such limitation. Some
jurisdictions do not allow the exclusion or limitation of incidental or
consequential damages, so this exclusion and limitation may not apply to You.

9) Acceptance and Termination. If You distribute copies of the Original Work or
a Derivative Work, You must make a reasonable effort under the circumstances to
obtain the express assent of recipients to the terms of this License. Nothing
else but this License (or another written agreement between Licensor and You)
grants You permission to create Derivative Works based upon the Original Work
or to exercise any of the rights granted in Section 1 herein, and any attempt
to do so except under the terms of this License (or another written agreement
between Licensor and You) is expressly prohibited by U.S. copyright law, the
equivalent laws of other countries, and by international treaty. Therefore, by
exercising any of the rights granted to You in Section 1 herein, You indicate
Your acceptance of this License and all of its terms and conditions.

10) Termination for Patent Action. This License shall terminate automatically
and You may no longer exercise any of the rights granted to You by this License
as of the date You commence an action, including a cross-claim or counterclaim,
against Licensor or any licensee alleging that the Original Work infringes a
patent. This termination provision shall not apply for an action alleging
patent infringement by combinations of the Original Work with other software or
hardware.

11) Jurisdiction, Venue and Governing Law. Any action or suit relating to this
License may be brought only in the courts of a jurisdiction wherein the
Licensor resides or in which Licensor conducts its primary business, and under
the laws of that jurisdiction excluding its conflict-of-law provisions. The
application of the United Nations Convention on Contracts for the International
Sale of Goods is expressly excluded. Any use of the Original Work outside the
scope of this License or after its termination shall be subject to the
requirements and penalties of the U.S. Copyright Act, 17 U.S.C. § 101 et
seq., the equivalent laws of other countries, and international treaty. This
section shall survive the termination of this License.

12) Attorneys Fees. In any action to enforce the terms of this License or
seeking damages relating thereto, the prevailing party shall be entitled to
recover its costs and expenses, including, without limitation, reasonable
attorneys' fees and costs incurred in connection with such action, including
any appeal of such action. This section shall survive the termination of this
License.

13) Miscellaneous. This License represents the complete agreement concerning
the subject matter hereof. If any provision of this License is held to be
unenforceable, such provision shall be reformed only to the extent necessary to
make it enforceable.

14) Definition of "You" in This License. "You" throughout this License, whether
in upper or lower case, means an individual or a legal entity exercising rights
under, and complying with all of the terms of, this License. For legal
entities, "You" includes any entity that controls, is controlled by, or is
under common control with you. For 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.

15) Right to Use. You may use the Original Work in all ways not otherwise
restricted or conditioned by this License or by law, and Licensor promises not
to interfere with or be responsible for such uses by You.

This license is Copyright (C) 2003-2004 Lawrence E. Rosen. All rights reserved.
Permission is hereby granted to copy and distribute this license without
modification. This license may not be modified without the express written
permission of its copyright owner.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
JSON Schema is a repository for the JSON Schema specification, reference schemas and a CommonJS implementation of JSON Schema (not the only JavaScript implementation of JSON Schema, JSV is another excellent JavaScript validator).
This is a historical repository for the early development of the JSON Schema specification and implementation. This package is considered "finished": it holds the earlier draft specification and a simple, efficient, lightweight implementation of the original core elements of JSON Schema. This repository does not house the latest specifications nor does it implement the latest versions of JSON Schema. This package seeks to maintain the stability (in behavior and size) of this original implementation for the sake of the numerous packages that rely on it. For the latest JSON Schema specifications and implementations, please visit the [JSON Schema site](https://json-schema.org/) (or the [respository](https://github.com/json-schema-org/json-schema-spec)).

Code is licensed under the AFL or BSD license as part of the Persevere
project which is administered under the Dojo foundation,
and all contributions require a Dojo CLA.
Code is licensed under the AFL or BSD 3-Clause license.
11 changes: 11 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Security Policy

## Supported Versions

| Version | Supported |
| ------- | ------------------ |
| 0.4.x | :white_check_mark: |

## Reporting a Vulnerability

Please report security vulnerabilities to kriszyp@gmail.com.
3 changes: 1 addition & 2 deletions lib/links.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* JSON Schema link handler
* Copyright (c) 2007 Kris Zyp SitePen (www.sitepen.com)
* Licensed under the MIT (MIT-LICENSE.txt) license.
* Licensed under AFL-2.1 OR BSD-3-Clause
*/
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
16 changes: 7 additions & 9 deletions lib/validate.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/**
* JSONSchema Validator - Validates JavaScript objects using JSON Schemas
* (http://www.json.com/json-schema-proposal/)
*
* Copyright (c) 2007 Kris Zyp SitePen (www.sitepen.com)
* Licensed under the MIT (MIT-LICENSE.txt) license.
* Licensed under AFL-2.1 OR BSD-3-Clause
To use the validator call the validate function with an instance object and an optional schema object.
If a schema is provided, it will be used to validate. If the instance object refers to a schema (self-validating),
that schema will be used to validate and the schema parameter is not necessary (if both exist,
@@ -107,7 +105,7 @@ var validate = exports._validate = function(/*Any*/instance,/*Object*/schema,/*O
!(value instanceof Array && type == 'array') &&
!(value instanceof Date && type == 'date') &&
!(type == 'integer' && value%1===0)){
return [{property:path,message:(typeof value) + " value found, but a " + type + " is required"}];
return [{property:path,message:value + " - " + (typeof value) + " value found, but a " + type + " is required"}];
}
if(type instanceof Array){
var unionErrors=[];
@@ -170,11 +168,11 @@ var validate = exports._validate = function(/*Any*/instance,/*Object*/schema,/*O
if(schema.minLength && typeof value == 'string' && value.length < schema.minLength){
addError("must be at least " + schema.minLength + " characters long");
}
if(typeof schema.minimum !== undefined && typeof value == typeof schema.minimum &&
if(typeof schema.minimum !== 'undefined' && typeof value == typeof schema.minimum &&
schema.minimum > value){
addError("must have a minimum value of " + schema.minimum);
}
if(typeof schema.maximum !== undefined && typeof value == typeof schema.maximum &&
if(typeof schema.maximum !== 'undefined' && typeof value == typeof schema.maximum &&
schema.maximum < value){
addError("must have a maximum value of " + schema.maximum);
}
@@ -209,8 +207,8 @@ var validate = exports._validate = function(/*Any*/instance,/*Object*/schema,/*O
}

for(var i in objTypeDef){
if(objTypeDef.hasOwnProperty(i)){
var value = instance[i];
if(objTypeDef.hasOwnProperty(i) && i != '__proto__' && i != 'constructor'){
var value = instance.hasOwnProperty(i) ? instance[i] : undefined;
// skip _not_ specified properties
if (value === undefined && options.existingOnly) continue;
var propDef = objTypeDef[i];
@@ -231,7 +229,7 @@ var validate = exports._validate = function(/*Any*/instance,/*Object*/schema,/*O
delete instance[i];
continue;
} else {
errors.push({property:path,message:(typeof value) + "The property " + i +
errors.push({property:path,message:"The property " + i +
" is not defined in the schema and the schema does not allow additional properties"});
}
}
17 changes: 5 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "json-schema",
"version": "0.2.3",
"version": "0.4.0",
"author": "Kris Zyp",
"description": "JSON Schema validation and specifications",
"maintainers":[
@@ -9,23 +9,16 @@
"json",
"schema"
],
"licenses": [
{
"type": "AFLv2.1",
"url": "http://trac.dojotoolkit.org/browser/dojo/trunk/LICENSE#L43"
},
{
"type": "BSD",
"url": "http://trac.dojotoolkit.org/browser/dojo/trunk/LICENSE#L13"
}
"files": [
"lib"
],
"license": "(AFL-2.1 OR BSD-3-Clause)",
"repository": {
"type":"git",
"url":"http://github.com/kriszyp/json-schema"
},
"directories": { "lib": "./lib" },
"main": "./lib/validate.js",
"devDependencies": { "vows": "*" },
"scripts": { "test": "echo TESTS DISABLED vows --spec test/*.js" }
"scripts": { "test": "vows --spec test/*.js" }
}

46 changes: 36 additions & 10 deletions test/tests.js
Original file line number Diff line number Diff line change
@@ -65,31 +65,57 @@ function assertSelfValidates(doc) {
topic: validate(schemas[doc]),
'returns valid result': resultIsValid(),
'with valid=true': function(result) { assert.equal(result.valid, true); },
'and no errors': function(result) { assert.length(result.errors, 0); }
'and no errors': function(result) { assert.equal(result.errors.length, 0); }
};

return context;
}

var suite = vows.describe('JSON Schema').addBatch({
'Core-NSD self-validates': assertSelfValidates('schema-nsd'),
'Core-NSD/Core-NSD': assertValidates('schema-nsd', 'schema-nsd'),
'Core-NSD/Core': assertValidates('schema-nsd', 'schema'),
//'Core-NSD/Core-NSD': assertValidates('schema-nsd', 'schema-nsd'),
//'Core-NSD/Core': assertValidates('schema-nsd', 'schema'),

'Core self-validates': assertSelfValidates('schema'),
'Core/Core': assertValidates('schema', 'schema'),
//'Core self-validates': assertSelfValidates('schema'),
//'Core/Core': assertValidates('schema', 'schema'),

'Hyper-NSD self-validates': assertSelfValidates('hyper-schema-nsd'),
'Hyper self-validates': assertSelfValidates('hyper-schema'),
'Hyper/Hyper': assertValidates('hyper-schema', 'hyper-schema'),
'Hyper/Core': assertValidates('hyper-schema', 'schema'),
//'Hyper self-validates': assertSelfValidates('hyper-schema'),
//'Hyper/Hyper': assertValidates('hyper-schema', 'hyper-schema'),
//'Hyper/Core': assertValidates('hyper-schema', 'schema'),

'Links-NSD self-validates': assertSelfValidates('links-nsd'),
'Links self-validates': assertSelfValidates('links'),
/*'Links self-validates': assertSelfValidates('links'),
'Links/Hyper': assertValidates('links', 'hyper-schema'),
'Links/Core': assertValidates('links', 'schema'),
'Json-Ref self-validates': assertSelfValidates('json-ref'),
'Json-Ref/Hyper': assertValidates('json-ref', 'hyper-schema'),
'Json-Ref/Core': assertValidates('json-ref', 'schema')
'Json-Ref/Core': assertValidates('json-ref', 'schema')*/
prototypePollution: function() {
console.log('testing')
const instance = JSON.parse(`
{
"$schema":{
"type": "object",
"properties":{
"__proto__": {
"type": "object",
"properties":{
"polluted": {
"type": "string",
"default": "polluted"
}
}
}
},
"__proto__": {}
}
}`);

const a = {};
validate(instance);
assert.equal(a.polluted, undefined);
}
}).export(module);