Skip to content

Commit 1089298

Browse files
committed
accept null for creationTime and software
1 parent 93eeca1 commit 1089298

4 files changed

Lines changed: 11 additions & 8 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Upgrading from 3.x? Upgrade to the latest 3.x release first, fix the deprecation
9292

9393
- **Invalid choices throw a `TypeError` naming the valid ones**: the resize `mode` (an `Error`, thrown once resizing started, so `resize({ fit: 'cover' })` could move a frame's offsets before failing), `composite()`'s `mode`, `flip()`, `disposalMode` and `wrapStyle` (`RangeError`s; an empty or `null` `wrapStyle` was the default).
9494

95-
- **No creation time and no version in encoded files by default**: the encoders only write a creation time when `metadata.creationTime` is given, so the same image encodes to the same bytes, and the default software is `'ImageScript'` without the version.
95+
- **No creation time and no version in encoded files by default**: the encoders only write a creation time when `metadata.creationTime` is given, so the same image encodes to the same bytes, and the default software is `'ImageScript'` without the version. `creationTime: null` and `software: null` leave the field out.
9696

9797
- **Drawing an SVG image that can't be drawn throws**: an `href` that isn't a data URI or one of the `images`, an image that can't be decoded (with the decoding error as its `cause`), an unsupported data URI type or an embedded SVG that can't be read throw once they are drawn (images in `<defs>` or hidden ones don't); they drew nothing before.
9898

‎guides/Migrating to 4.0.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ blocks that check for `RangeError` around `resize()`, `composite()`, `flip()` an
235235
In 3.x, every encoder wrote the time of encoding as the creation time and `ImageScript vX.Y.Z` as the software, so the
236236
same image never encoded to the same bytes twice, and every file told which release made it. In 4.0, the creation time
237237
is only written when `metadata.creationTime` is given, and the default software is `'ImageScript'`, without a version
238-
(`software: ''` still leaves it out):
238+
(`software: null` leaves it out):
239239

240240
| 3.x | 4.0 |
241241
| --- | --- |

‎src/metadata.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import * as exif from './codecs/exif.ts';
1212
* | GIF | software, comment (comment extensions) |
1313
* | TGA | author, comment, creation time, software (extension area) |
1414
*
15-
* Empty fields are left out. Without metadata, the files only say which software made them (`software`), so the same
15+
* Empty fields (and `null` ones) are left out. Without metadata, the files only say which software made them (`software`), so the same
1616
* image always encodes to the same bytes
1717
*/
1818
export interface Metadata {
@@ -24,10 +24,10 @@ export interface Metadata {
2424
description?: string;
2525
/** The image's copyright info */
2626
copyright?: string;
27-
/** The image's creation time. Default: none (left out) */
28-
creationTime?: string | number | Date;
29-
/** The software used to create the image. Default: `'ImageScript'` (without a version), `''` leaves it out */
30-
software?: string;
27+
/** The image's creation time. Default: none (`null` leaves it out, too) */
28+
creationTime?: string | number | Date | null;
29+
/** The software used to create the image. Default: `'ImageScript'` (without a version), `null` leaves it out */
30+
software?: string | null;
3131
/** A disclaimer for the image */
3232
disclaimer?: string;
3333
/** A warning for the image */
@@ -64,7 +64,7 @@ const TEXT_FIELDS = ['title', 'author', 'description', 'copyright', 'software',
6464
export function resolveMetadata(metadata: Metadata = {}): ResolvedMetadata {
6565
const { creationTime, software } = metadata || {};
6666
const resolved: ResolvedMetadata = {};
67-
if (creationTime !== undefined) {
67+
if (creationTime !== undefined && creationTime !== null) {
6868
const time = new Date(creationTime);
6969
if (isNaN(time.getTime())) throw new RangeError('Invalid creation time');
7070
resolved.creationTime = time;

‎tests/metadata.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ const latin1 = (data, text) => Buffer.from(data).includes(Buffer.from(text, 'lat
4040
Date.now = now;
4141
if (!Buffer.from(early).equals(Buffer.from(late))) panic(`${format}: encoding depends on the time`);
4242
if (has(await encode({software: ''}), 'ImageScript')) panic(`${format}: software: '' should leave it out`);
43+
if (has(await encode({software: null}), 'ImageScript')) panic(`${format}: software: null should leave it out`);
44+
// (null is no time: not the epoch)
45+
if (!Buffer.from(await encode({creationTime: null})).equals(Buffer.from(await encode({})))) panic(`${format}: creationTime: null should be the default`);
4346
if (!has(await encode({software: 'custom tool'}), 'custom tool')) panic(`${format}: custom software missing`);
4447

4548
const decoded = /gif|apng|animated/.test(format) ? (await Animation.decode(tagged)).frames[0] : await Image.decode(tagged);

0 commit comments

Comments
 (0)