Skip to content

Commit

Permalink
fix: remove null bytes before inserting inscriptions (#274)
Browse files Browse the repository at this point in the history
* fix: remove null bytes before inserting inscriptions

* fix: also on content type
  • Loading branch information
rafaelcr authored Nov 20, 2023
1 parent 2dde6e0 commit cec3de0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/pg/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,8 @@ export function throwOnFirstRejected<T extends any[]>(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, '');
}
9 changes: 5 additions & 4 deletions src/pg/pg-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit cec3de0

Please sign in to comment.