-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #217 from bhollis/fix-floats
Fixed a regression where floating-point numbers were truncated to integers
- Loading branch information
Showing
8 changed files
with
128 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"id": "[email protected]", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"name": "jsonview", | ||
"title": "JSONView", | ||
"description": "View JSON documents in the browser.", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { strict as assert } from "node:assert"; | ||
import test from "node:test"; | ||
import { valueToHTML } from "./jsonformatter.js"; | ||
import { safeStringEncodeNums } from "./safe-encode-numbers.js"; | ||
|
||
const jsonContent = [ | ||
[`{}`, `{ }`], | ||
[ | ||
`{ "hey": "guy" }`, | ||
`<span class="collapser"></span>{<ul class="obj collapsible"><li><span class="spacer"> </span><span class="prop" title="<root>.hey"><span class="q">"</span>hey<span class="q">"</span></span>: <span class="string">"guy"</span></li></ul><span class="spacer"></span>}`, | ||
], | ||
[ | ||
`{ "float": 10.5 }`, | ||
`<span class="collapser"></span>{<ul class="obj collapsible"><li><span class="spacer"> </span><span class="prop" title="<root>.float"><span class="q">"</span>float<span class="q">"</span></span>: <span class="num">10.5</span></li></ul><span class="spacer"></span>}`, | ||
], | ||
[ | ||
`{ "10.5": "hello" }`, | ||
`<span class="collapser"></span>{<ul class="obj collapsible"><li><span class="spacer"> </span><span class="prop quoted" title=""><span class="q">"</span>10.5<span class="q">"</span></span>: <span class="string">"hello"</span></li></ul><span class="spacer"></span>}`, | ||
], | ||
[ | ||
// bigger than max safe integer | ||
`{ "anumber": 9117199254740991 }`, | ||
`<span class="collapser"></span>{<ul class="obj collapsible"><li><span class="spacer"> </span><span class="prop" title="<root>.anumber"><span class="q">"</span>anumber<span class="q">"</span></span>: <span class="num">9117199254740992</span></li></ul><span class="spacer"></span>}`, | ||
], | ||
[ | ||
`{ "anobject": {"whoa": "nuts","anarray": [1,2,"thr<h1>ee"], "more":"stuff"} }`, | ||
`<span class="collapser"></span>{<ul class="obj collapsible"><li><span class="spacer"> </span><span class="prop" title="<root>.anobject"><span class="q">"</span>anobject<span class="q">"</span></span>: <span class="collapser"></span>{<ul class="obj collapsible"><li><span class="spacer"> </span><span class="prop" title="<root>.anobject.whoa"><span class="q">"</span>whoa<span class="q">"</span></span>: <span class="string">"nuts"</span>,</li><li><span class="spacer"> </span><span class="prop" title="<root>.anobject.anarray"><span class="q">"</span>anarray<span class="q">"</span></span>: <span class="collapser"></span>[<ul class="array collapsible"><li><span class="spacer"> </span><span class="num">1</span>,</li><li><span class="spacer"> </span><span class="num">2</span>,</li><li><span class="spacer"> </span><span class="string">"thr<h1>ee"</span></li></ul><span class="spacer"> </span>],</li><li><span class="spacer"> </span><span class="prop" title="<root>.anobject.more"><span class="q">"</span>more<span class="q">"</span></span>: <span class="string">"stuff"</span></li></ul><span class="spacer"> </span>}</li></ul><span class="spacer"></span>}`, | ||
], | ||
[ | ||
`{ "awesome": true }`, | ||
`<span class="collapser"></span>{<ul class="obj collapsible"><li><span class="spacer"> </span><span class="prop" title="<root>.awesome"><span class="q">"</span>awesome<span class="q">"</span></span>: <span class="bool">true</span></li></ul><span class="spacer"></span>}`, | ||
], | ||
[ | ||
`{ "bogus": false }`, | ||
`<span class="collapser"></span>{<ul class="obj collapsible"><li><span class="spacer"> </span><span class="prop" title="<root>.bogus"><span class="q">"</span>bogus<span class="q">"</span></span>: <span class="bool">false</span></li></ul><span class="spacer"></span>}`, | ||
], | ||
[ | ||
`{ "meaning": null }`, | ||
`<span class="collapser"></span>{<ul class="obj collapsible"><li><span class="spacer"> </span><span class="prop" title="<root>.meaning"><span class="q">"</span>meaning<span class="q">"</span></span>: <span class="null">null</span></li></ul><span class="spacer"></span>}`, | ||
], | ||
[ | ||
`{ "japanese": "明日がある。" }`, | ||
`<span class="collapser"></span>{<ul class="obj collapsible"><li><span class="spacer"> </span><span class="prop" title="<root>.japanese"><span class="q">"</span>japanese<span class="q">"</span></span>: <span class="string">"明日がある。"</span></li></ul><span class="spacer"></span>}`, | ||
], | ||
[ | ||
`{ "link": "http://jsonview.com" }`, | ||
`<span class="collapser"></span>{<ul class="obj collapsible"><li><span class="spacer"> </span><span class="prop" title="<root>.link"><span class="q">"</span>link<span class="q">"</span></span>: <a href="http://jsonview.com"><span class="q">"</span>http://jsonview.com<span class="q">"</span></a></li></ul><span class="spacer"></span>}`, | ||
], | ||
[ | ||
`{ "notLink": "http://jsonview.com is great" }`, | ||
`<span class="collapser"></span>{<ul class="obj collapsible"><li><span class="spacer"> </span><span class="prop" title="<root>.notLink"><span class="q">"</span>notLink<span class="q">"</span></span>: <span class="string">"http://jsonview.com is great"</span></li></ul><span class="spacer"></span>}`, | ||
], | ||
[ | ||
`{ "aZero": 0 }`, | ||
`<span class="collapser"></span>{<ul class="obj collapsible"><li><span class="spacer"> </span><span class="prop" title="<root>.aZero"><span class="q">"</span>aZero<span class="q">"</span></span>: <span class="num">0</span></li></ul><span class="spacer"></span>}`, | ||
], | ||
[ | ||
`{ "emptyString": "" }`, | ||
`<span class="collapser"></span>{<ul class="obj collapsible"><li><span class="spacer"> </span><span class="prop" title="<root>.emptyString"><span class="q">"</span>emptyString<span class="q">"</span></span>: <span class="string">""</span></li></ul><span class="spacer"></span>}`, | ||
], | ||
[ | ||
`{"string_with_nulls":"\\u0000*\\u0000_hello"}`, | ||
`<span class="collapser"></span>{<ul class="obj collapsible"><li><span class="spacer"> </span><span class="prop" title="<root>.string_with_nulls"><span class="q">"</span>string_with_nulls<span class="q">"</span></span>: <span class="string">"\\u0000*\\u0000_hello"</span></li></ul><span class="spacer"></span>}`, | ||
], | ||
[ | ||
`{"":"18"}`, | ||
`<span class="collapser"></span>{<ul class="obj collapsible"><li><span class="spacer"> </span><span class="prop quoted" title=""><span class="q">"</span><span class="q">"</span></span>: <span class="string">"18"</span></li></ul><span class="spacer"></span>}`, | ||
], | ||
[`[]`, `[ ]`], | ||
[`null`, `<span class="null">null</span>`], | ||
[`true`, `<span class="bool">true</span>`], | ||
[`1`, `<span class="num">1</span>`], | ||
[ | ||
`[1,2,"thr<h1>ee"]`, | ||
`<span class="collapser"></span>[<ul class="array collapsible"><li><span class="spacer"> </span><span class="num">1</span>,</li><li><span class="spacer"> </span><span class="num">2</span>,</li><li><span class="spacer"> </span><span class="string">"thr<h1>ee"</span></li></ul><span class="spacer"></span>]`, | ||
], | ||
[ | ||
`{"hey": "g'uy'"}`, | ||
`<span class="collapser"></span>{<ul class="obj collapsible"><li><span class="spacer"> </span><span class="prop" title="<root>.hey"><span class="q">"</span>hey<span class="q">"</span></span>: <span class="string">"g'uy'"</span></li></ul><span class="spacer"></span>}`, | ||
], | ||
[ | ||
`{ "value":[ { "@some.text":"W/\\"12241774\\"" } ] }`, | ||
`<span class="collapser"></span>{<ul class="obj collapsible"><li><span class="spacer"> </span><span class="prop" title="<root>.value"><span class="q">"</span>value<span class="q">"</span></span>: <span class="collapser"></span>[<ul class="array collapsible"><li><span class="spacer"> </span><span class="collapser"></span>{<ul class="obj collapsible"><li><span class="spacer"> </span><span class="prop quoted" title=""><span class="q">"</span>@some.text<span class="q">"</span></span>: <span class="string">"W/\\"12241774\\""</span></li></ul><span class="spacer"> </span>}</li></ul><span class="spacer"> </span>]</li></ul><span class="spacer"></span>}`, | ||
], | ||
[ | ||
`{"key":"\\"value\\u201d"}`, | ||
`<span class="collapser"></span>{<ul class="obj collapsible"><li><span class="spacer"> </span><span class="prop" title="<root>.key"><span class="q">"</span>key<span class="q">"</span></span>: <span class="string">"\\"value”"</span></li></ul><span class="spacer"></span>}`, | ||
], | ||
]; | ||
|
||
Object.defineProperties(globalThis, { | ||
chrome: { | ||
value: { | ||
i18n: { | ||
getMessage: (message: string) => message, | ||
}, | ||
runtime: { | ||
getURL: (url: string) => url, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
for (const [content, result] of jsonContent) { | ||
test(`valueToHTML ${content}`, () => { | ||
assert.equal(valueToHTML(JSON.parse(safeStringEncodeNums(content)), "<root>", 0), result); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"manifest_version": 3, | ||
"name": "JSONView", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "__MSG_extensionDescription__", | ||
"author": "Benjamin Hollis", | ||
"homepage_url": "https://jsonview.com/", | ||
|
@@ -12,6 +12,11 @@ | |
"128": "icon128.png", | ||
"256": "icon256.png" | ||
}, | ||
"browser_specific_settings": { | ||
"gecko": { | ||
"id": "[email protected]" | ||
} | ||
}, | ||
"background": { | ||
"scripts": ["background.js"], | ||
"type": "module" | ||
|