IF Commons GitHub

xml

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0002-anyfs-s3-store FR-003

The XML that S3 answers with, read by a small strict reader and not a general one. It reads one root element with its children, attributes (kept for nobody), text and the five named entities and the numeric ones, and it refuses everything an answer of S3 never has and an attacker would use: a document type (and so every entity of its own), a comment, CDATA, a processing instruction after the declaration, a name or an entity it does not know, a character XML 1.0 does not allow, more than a bound of bytes, depth or nodes, and text after the root. The two shapes the store needs are read from the tree: a ListObjectsV2 answer and an error.

import { parseXml } from "./xml.ts";
const r = parseXml("<Error><Code>NoSuchKey</Code><Message>gone</Message></Error>");
r.kind === "ok" && r.value.children[0]?.text; // "NoSuchKey"

Source: commons/anyfs-s3/src/xml.ts

4 of 9 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

DEFAULT_LIMITSconst
const DEFAULT_LIMITS: XmlLimits

The bounds of an answer of S3: a list of a thousand keys is far below them.

Imported by 6 tests of the run (6 passed, 0 failed): the library's results

ErrorBodytypeno test imports it
type ErrorBody = { readonly code: string; readonly message: string; readonly requestId?: string };

What S3 says of a failure.

ListPagetypeno test imports it
type ListPage = { readonly objects: readonly Listed[]; readonly truncated: boolean; readonly next?: string };

A page of ListObjectsV2: the objects in the order S3 gave them, and the token to go on where there are more.

Listedtypeno test imports it
type Listed = { readonly key: string; readonly size: number; readonly etag: string; readonly modified?: string };

One object of a listing.

parseErrorBodyfunction
function parseErrorBody(source: string): Result<ErrorBody, string>

The code and message of the XML of an error.

Imported by 6 tests of the run (6 passed, 0 failed): the library's results

parseListingfunction
function parseListing(source: string): Result<ListPage, string>

A listing read from the XML of ListObjectsV2, with each key as the answer gave it (still encoded where encoding-type=url was asked).

Imported by 6 tests of the run (6 passed, 0 failed): the library's results

parseXmlfunction
function parseXml(source: string, limits?: XmlLimits): Result<XmlNode, string>

The one root element of a document, or why the text is not a document this reader takes.

Imported by 6 tests of the run (6 passed, 0 failed): the library's results

XmlLimitstypeno test imports it
type XmlLimits = { readonly maxBytes: number; readonly maxDepth: number; readonly maxNodes: number };

What a document may be.

XmlNodetypeno test imports it
type XmlNode = { readonly name: string; readonly text: string; readonly children: readonly XmlNode[] };

An element: its name without a namespace prefix, its text where it has no children, and its children in order.

Titles, headings, exports, tables, columns and requirements. Esc closes.