Skip to content

Commit 88b7b74

Browse files
committed
Fix #599 catch invalid lore lines
1 parent 586c777 commit 88b7b74

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/app/components/ItemTooltip.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export function ItemTooltip({ item, advanced, resolver }: Props) {
115115
: <TextComponent component={{ translate: 'item.dyed', color: 'gray' }} />
116116
)}
117117
{item.getLore().map((component) =>
118-
<TextComponent component={JSON.parse(component)} base={{ color: 'dark_purple', italic: true }} />
118+
<TextComponent component={component} base={{ color: 'dark_purple', italic: true }} />
119119
)}
120120
{item.showInTooltip('attribute_modifiers') && (
121121
<AttributeModifiersTooltip data={item.get('attribute_modifiers', tag => tag)} />

src/app/services/ResolvedItem.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,13 @@ export class ResolvedItem extends ItemStack {
107107

108108
public getLore() {
109109
return this.get('lore', tag => {
110-
return tag.isList() ? tag.map(e => e.getAsString()) : []
110+
return tag.isList() ? tag.map(e => {
111+
try {
112+
return JSON.parse(e.getAsString())
113+
} catch (e) {
114+
return { text: '(invalid lore line)' }
115+
}
116+
}) : []
111117
}) ?? []
112118
}
113119

@@ -160,11 +166,13 @@ export class ResolvedItem extends ItemStack {
160166
}
161167

162168
const itemName = this.get('item_name', tag => tag.isString() ? tag.getAsString() : undefined)
163-
try {
164-
if (itemName) {
169+
if (itemName) {
170+
try {
165171
return JSON.parse(itemName)
172+
} catch (e) {
173+
return { text: '(invalid item name)' }
166174
}
167-
} catch (e) {}
175+
}
168176

169177
const guess = this.id.path
170178
.replace(/[_\/]/g, ' ')

0 commit comments

Comments
 (0)