Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
add <script fundme> throw logic if MIME type not json
Browse files Browse the repository at this point in the history
  • Loading branch information
totorogendut committed Mar 27, 2020
1 parent 6169853 commit dd23a44
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 5 deletions.
2 changes: 2 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## unreleased

- Add examples for using fundme.js in the browser.
- Now `<script fundme>` will throw an error if its type not `application/json`.
- Test: add test for `<script fundme>` type.

## 0.0.3

Expand Down
4 changes: 4 additions & 0 deletions dist/fundme-amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ define(['exports'], function (exports) { 'use strict';
// script json template
const cannotParseScriptJson = 'Fundme.js: cannot parse JSON from <script fundme>. Make sure it contains a valid JSON.';
const jsonTemplateIsNotArray = "Fundme.js: found <script fundme> but it's not an array.";
const scriptFundmeIsNotApplicationJson = 'Fundme.js: found <script fundme> but its type is not "application/json"';

const DEFAULT_WEIGHT = 5;
// TODO check pointer.address with RegEx
Expand Down Expand Up @@ -144,6 +145,9 @@ define(['exports'], function (exports) { 'use strict';
catch (err) {
throw new Error(cannotParseScriptJson);
}
if (json.type !== 'application/json') {
throw new Error(scriptFundmeIsNotApplicationJson);
}
if (Array.isArray(pointers)) {
pointers = createPool(pointers);
}
Expand Down
2 changes: 1 addition & 1 deletion dist/fundme-amd.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/fundme-cjs-compat.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions dist/fundme-cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const failParsingTemplate = 'Fundme.js: fails to parse address from <template da
// script json template
const cannotParseScriptJson = 'Fundme.js: cannot parse JSON from <script fundme>. Make sure it contains a valid JSON.';
const jsonTemplateIsNotArray = "Fundme.js: found <script fundme> but it's not an array.";
const scriptFundmeIsNotApplicationJson = 'Fundme.js: found <script fundme> but its type is not "application/json"';

const DEFAULT_WEIGHT = 5;
// TODO check pointer.address with RegEx
Expand Down Expand Up @@ -146,6 +147,9 @@ function parseScriptJson(json) {
catch (err) {
throw new Error(cannotParseScriptJson);
}
if (json.type !== 'application/json') {
throw new Error(scriptFundmeIsNotApplicationJson);
}
if (Array.isArray(pointers)) {
pointers = createPool(pointers);
}
Expand Down
Loading

0 comments on commit dd23a44

Please sign in to comment.