Filter malformed tags

This commit is contained in:
Kieran 2023-01-05 20:43:34 +00:00
parent 6a28f2dc5a
commit ae133130ef
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
2 changed files with 14 additions and 1 deletions

View File

@ -5,6 +5,11 @@ import Thread from './Thread';
export default class Event {
constructor() {
/**
* The original event
*/
this.Original = null;
/**
* Id of the event
* @type {string}
@ -117,11 +122,12 @@ export default class Event {
}
let ret = new Event();
ret.Original = obj;
ret.Id = obj.id;
ret.PubKey = obj.pubkey;
ret.CreatedAt = obj.created_at;
ret.Kind = obj.kind;
ret.Tags = obj.tags.map((e, i) => new Tag(e, i));
ret.Tags = obj.tags.map((e, i) => new Tag(e, i)).filter(a => !a.Invalid);
ret.Content = obj.content;
ret.Signature = obj.sig;
return ret;

View File

@ -7,6 +7,7 @@ export default class Tag {
this.Marker = null;
this.Other = null;
this.Index = index;
this.Invalid = false;
switch (this.Key) {
case "e": {
@ -14,11 +15,17 @@ export default class Tag {
this.Event = tag[1];
this.Relay = tag.length > 2 ? tag[2] : null;
this.Marker = tag.length > 3 ? tag[3] : null;
if (!this.Event) {
this.Invalid = true;
}
break;
}
case "p": {
// ["p", <pubkey>]
this.PubKey = tag[1];
if (!this.PubKey) {
this.Invalid = true;
}
break;
}
default: {