Filter malformed tags
This commit is contained in:
parent
6a28f2dc5a
commit
ae133130ef
|
@ -5,6 +5,11 @@ import Thread from './Thread';
|
||||||
|
|
||||||
export default class Event {
|
export default class Event {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
/**
|
||||||
|
* The original event
|
||||||
|
*/
|
||||||
|
this.Original = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Id of the event
|
* Id of the event
|
||||||
* @type {string}
|
* @type {string}
|
||||||
|
@ -117,11 +122,12 @@ export default class Event {
|
||||||
}
|
}
|
||||||
|
|
||||||
let ret = new Event();
|
let ret = new Event();
|
||||||
|
ret.Original = obj;
|
||||||
ret.Id = obj.id;
|
ret.Id = obj.id;
|
||||||
ret.PubKey = obj.pubkey;
|
ret.PubKey = obj.pubkey;
|
||||||
ret.CreatedAt = obj.created_at;
|
ret.CreatedAt = obj.created_at;
|
||||||
ret.Kind = obj.kind;
|
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.Content = obj.content;
|
||||||
ret.Signature = obj.sig;
|
ret.Signature = obj.sig;
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -7,6 +7,7 @@ export default class Tag {
|
||||||
this.Marker = null;
|
this.Marker = null;
|
||||||
this.Other = null;
|
this.Other = null;
|
||||||
this.Index = index;
|
this.Index = index;
|
||||||
|
this.Invalid = false;
|
||||||
|
|
||||||
switch (this.Key) {
|
switch (this.Key) {
|
||||||
case "e": {
|
case "e": {
|
||||||
|
@ -14,11 +15,17 @@ export default class Tag {
|
||||||
this.Event = tag[1];
|
this.Event = tag[1];
|
||||||
this.Relay = tag.length > 2 ? tag[2] : null;
|
this.Relay = tag.length > 2 ? tag[2] : null;
|
||||||
this.Marker = tag.length > 3 ? tag[3] : null;
|
this.Marker = tag.length > 3 ? tag[3] : null;
|
||||||
|
if (!this.Event) {
|
||||||
|
this.Invalid = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "p": {
|
case "p": {
|
||||||
// ["p", <pubkey>]
|
// ["p", <pubkey>]
|
||||||
this.PubKey = tag[1];
|
this.PubKey = tag[1];
|
||||||
|
if (!this.PubKey) {
|
||||||
|
this.Invalid = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
|
Loading…
Reference in New Issue