Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "quadstore",
"version": "15.2.0",
"version": "15.3.0-beta.1",
"description": "Quadstore is a LevelDB-backed RDF graph database / triplestore for JavaScript runtimes (browsers, Node.js, Deno, Bun, ...) that implements the RDF/JS interfaces and supports SPARQL queries and querying across named graphs.",
"keywords": [
"node",
Expand Down
5 changes: 4 additions & 1 deletion src/serialization/fpstring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
* +------+------------+-----------------------------------------+--------------------+------------+
* | 6 | Infinity | | | |
* +------+------------+-----------------------------------------+--------------------+------------+
* | 7 | NaN | | | |
* +------+------------+-----------------------------------------+--------------------+------------+
*
*/

Expand All @@ -64,6 +66,7 @@ const join = (encodingCase: number, exponent: number, mantissa: number): string
const ZERO = join(3, 0, 0);
const NEG_INF = join(0, 0, 0);
const POS_INF = join(6, 0, 0);
const NAN = join(7, 0, 0);

export const encode = (stringOrNumber: string|number): string => {

Expand All @@ -72,7 +75,7 @@ export const encode = (stringOrNumber: string|number): string => {
: stringOrNumber;

if (Number.isNaN(mantissa)) {
throw new Error(`Cannot serialize NaN`);
return NAN;
}

if (mantissa === -Infinity) {
Expand Down
1 change: 1 addition & 0 deletions src/serialization/terms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export const termWriter: TermWriter<Term, 'F'> = {
stringLiteralWriter.write(term, serialized, prefixes);
break;
case xsd.integer:
case xsd.float:
case xsd.double:
case xsd.decimal:
case xsd.nonPositiveInteger:
Expand Down
1 change: 1 addition & 0 deletions src/serialization/xsd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const boolean = `${xsd}boolean`;

export const integer = `${xsd}integer`;
export const decimal = `${xsd}decimal`;
export const float = `${xsd}float`;
export const double = `${xsd}double`;
export const nonPositiveInteger = `${xsd}nonPositiveInteger`;
export const negativeInteger = `${xsd}negativeInteger`;
Expand Down
15 changes: 15 additions & 0 deletions test/quadstore/serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,21 @@ export const runSerializationTests = () => {
toEqualQuad(read, quad);
});
});

it('Should serialize and deserialize a quad having a NaN literal term', async function () {
const { store: { dataFactory: factory, indexes }, prefixes } = this;
const quad = factory.quad(
factory.namedNode('http://ex.com/s'),
factory.namedNode('http://ex.com/p'),
factory.literal('NaN', factory.namedNode(xsd.double)),
factory.namedNode('http://ex.com/g'),
);
indexes.forEach((index: InternalIndex) => {
const key = twoStepsQuadWriter.ingest(quad, prefixes).write(index.prefix, index.terms);
const read = quadReader.read(key, index.prefix.length, index.terms, factory, prefixes);
toEqualQuad(read, quad);
});
});

});

Expand Down