From cec3de061a5b475161b2d11369fc13b63ad8bc27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20C=C3=A1rdenas?= Date: Sun, 19 Nov 2023 18:16:02 -0600 Subject: [PATCH] fix: remove null bytes before inserting inscriptions (#274) * fix: remove null bytes before inserting inscriptions * fix: also on content type --- src/pg/helpers.ts | 5 +++++ src/pg/pg-store.ts | 9 +++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/pg/helpers.ts b/src/pg/helpers.ts index 5506bedc..443b45d2 100644 --- a/src/pg/helpers.ts +++ b/src/pg/helpers.ts @@ -64,3 +64,8 @@ export function throwOnFirstRejected(settles: { export function objRemoveUndefinedValues(obj: object) { Object.keys(obj).forEach(key => (obj as any)[key] === undefined && delete (obj as any)[key]); } + +export function removeNullBytes(input: string): string { + // Replace null byte with an empty string + return input.replace(/\x00/g, ''); +} diff --git a/src/pg/pg-store.ts b/src/pg/pg-store.ts index 93ae558b..6616c33e 100644 --- a/src/pg/pg-store.ts +++ b/src/pg/pg-store.ts @@ -18,7 +18,7 @@ import { ENV } from '../env'; import { Brc20PgStore } from './brc20/brc20-pg-store'; import { CountsPgStore } from './counts/counts-pg-store'; import { getIndexResultCountType } from './counts/helpers'; -import { assertNoBlockInscriptionGap, getInscriptionRecursion } from './helpers'; +import { assertNoBlockInscriptionGap, getInscriptionRecursion, removeNullBytes } from './helpers'; import { DbFullyLocatedInscriptionResult, DbInscription, @@ -185,14 +185,15 @@ export class PgStore extends BasePgStore { const satoshi = new OrdinalSatoshi(reveal.ordinal_number); const satpoint = parseSatPoint(reveal.satpoint_post_inscription); const recursive_refs = getInscriptionRecursion(reveal.content_bytes); + const contentType = removeNullBytes(reveal.content_type); writes.push({ inscription: { genesis_id: reveal.inscription_id, - mime_type: reveal.content_type.split(';')[0], - content_type: reveal.content_type, + mime_type: contentType.split(';')[0], + content_type: contentType, content_length: reveal.content_length, number: reveal.inscription_number, - content: reveal.content_bytes, + content: removeNullBytes(reveal.content_bytes), fee: reveal.inscription_fee.toString(), curse_type: JSON.stringify(reveal.curse_type), sat_ordinal: reveal.ordinal_number.toString(),