Skip to content

Commit 49a9fc7

Browse files
authored
v4.0.4
catch undefined absolut URI
2 parents bbbd4a0 + 79bf9b2 commit 49a9fc7

File tree

5 files changed

+43
-10
lines changed

5 files changed

+43
-10
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "solid-logic",
3-
"version": "4.0.3",
3+
"version": "4.0.4",
44
"description": "Core business logic of SolidOS",
55
"type": "module",
66
"main": "dist/solid-logic.js",

src/typeIndex/typeIndexLogic.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import { newThing } from '../util/utils'
77
export function createTypeIndexLogic(store, authn, profileLogic, utilityLogic): TypeIndexLogic {
88
const ns = namespace
99

10+
function isAbsoluteHttpUri(uri: string | null | undefined): boolean {
11+
return !!uri && (uri.startsWith('https://') || uri.startsWith('http://'))
12+
}
13+
1014
function getRegistrations(instance, theClass) {
1115
return store
1216
.each(undefined, ns.solid('instance'), instance)
@@ -82,7 +86,7 @@ export function createTypeIndexLogic(store, authn, profileLogic, utilityLogic):
8286
return scopes
8387
}
8488

85-
async function loadCommunityTypeIndexes(user: NamedNode): Promise<TypeIndexScope[][]> {
89+
async function loadCommunityTypeIndexes(user: NamedNode): Promise<TypeIndexScope[]> {
8690
let preferencesFile
8791
try {
8892
preferencesFile = await profileLogic.silencedLoadPreferences(user)
@@ -96,15 +100,23 @@ export function createTypeIndexLogic(store, authn, profileLogic, utilityLogic):
96100
)
97101
let result = []
98102
for (const org of communities) {
99-
result = result.concat(await loadTypeIndexesFor(org as NamedNode) as any)
103+
if (org.termType !== 'NamedNode' || !isAbsoluteHttpUri((org as NamedNode).uri)) {
104+
debug.warn(`Skipping malformed community node for ${user}: ${org}`)
105+
continue
106+
}
107+
try {
108+
result = result.concat(await loadTypeIndexesFor(org as NamedNode) as any)
109+
} catch (err) {
110+
debug.warn(`Skipping community type indexes for ${(org as NamedNode).uri}: ${err}`)
111+
}
100112
}
101113
return result
102114
}
103115
return [] // No communities
104116
}
105117

106118
async function loadAllTypeIndexes(user: NamedNode) {
107-
return (await loadTypeIndexesFor(user)).concat((await loadCommunityTypeIndexes(user)).flat())
119+
return (await loadTypeIndexesFor(user)).concat(await loadCommunityTypeIndexes(user))
108120
}
109121

110122
async function getScopedAppInstances(klass: NamedNode, user: NamedNode): Promise<ScopedApp[]> {
@@ -130,10 +142,10 @@ export function createTypeIndexLogic(store, authn, profileLogic, utilityLogic):
130142
function docDirUri(node: NamedNode): string | null {
131143
const doc = node.doc()
132144
const dir = doc.dir()
133-
if (dir?.uri) return dir.uri
145+
if (dir?.uri && isAbsoluteHttpUri(dir.uri)) return dir.uri
134146
const docUri = doc.uri
135-
if (!docUri) {
136-
debug.log(`docDirUri: missing doc uri for ${node?.uri}`)
147+
if (!docUri || !isAbsoluteHttpUri(docUri)) {
148+
debug.log(`docDirUri: missing or non-http(s) doc uri for ${node?.uri}`)
137149
return null
138150
}
139151
const withoutFragment = docUri.split('#')[0]

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export interface InboxLogic {
9696
export interface TypeIndexLogic {
9797
getRegistrations: (instance, theClass) => Node[],
9898
loadTypeIndexesFor: (user: NamedNode) => Promise<Array<TypeIndexScope>>,
99-
loadCommunityTypeIndexes: (user: NamedNode) => Promise<TypeIndexScope[][]>,
99+
loadCommunityTypeIndexes: (user: NamedNode) => Promise<Array<TypeIndexScope>>,
100100
loadAllTypeIndexes: (user: NamedNode) => Promise<Array<TypeIndexScope>>,
101101
getScopedAppInstances: (klass: NamedNode, user: NamedNode) => Promise<ScopedApp[]>,
102102
getAppInstances: (klass: NamedNode) => Promise<NamedNode[]>,

test/typeIndexLogic.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,27 @@ describe('TypeIndex logic NEW', () => {
170170
const result = await typeIndexLogic.loadCommunityTypeIndexes(alice)
171171
expect(result).toEqual(ClubScopes)
172172
})
173+
it('skips malformed non-NamedNode community entries', async () => {
174+
web[AlicePreferencesFile.uri] = `
175+
${alice} solid:privateTypeIndex ${AlicePrivateTypeIndex};
176+
solid:community ${club};
177+
solid:community "not-a-webid" .
178+
`
179+
180+
const result = await typeIndexLogic.loadCommunityTypeIndexes(alice)
181+
expect(result).toEqual(ClubScopes)
182+
})
183+
it('continues when one community fails to load', async () => {
184+
const brokenCommunity = sym('https://broken.example.com/profile/card.ttl#it')
185+
web[AlicePreferencesFile.uri] = `
186+
${alice} solid:privateTypeIndex ${AlicePrivateTypeIndex};
187+
solid:community ${brokenCommunity};
188+
solid:community ${club} .
189+
`
190+
191+
const result = await typeIndexLogic.loadCommunityTypeIndexes(alice)
192+
expect(result).toEqual(ClubScopes)
193+
})
173194
})
174195

175196
const AliceAndClubScopes = [{'instance': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/publicStuff/actionItems.ttl#this'}, 'scope': {'agent': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/profile/card.ttl#me'}, 'index': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/profile/public-type-index.ttl'}, 'label': 'public'}, 'type': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'http://www.w3.org/2005/01/wf/flow#Tracker'}}, {'instance': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/project4/issues.ttl#this'}, 'scope': {'agent': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/profile/card.ttl#me'}, 'index': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/profile/public-type-index.ttl'}, 'label': 'public'}, 'type': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'http://www.w3.org/2005/01/wf/flow#Tracker'}}, {'instance': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/privateStuff/ToDo.ttl#this'}, 'scope': {'agent': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/profile/card.ttl#me'}, 'index': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/settings/private-type-index.ttl'}, 'label': 'private'}, 'type': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'http://www.w3.org/2005/01/wf/flow#Tracker'}}, {'instance': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/privateStuff/Goals.ttl#this'}, 'scope': {'agent': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/profile/card.ttl#me'}, 'index': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/settings/private-type-index.ttl'}, 'label': 'private'}, 'type': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'http://www.w3.org/2005/01/wf/flow#Tracker'}}, {'instance': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/privateStuff/workingOn.ttl#this'}, 'scope': {'agent': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/profile/card.ttl#me'}, 'index': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/settings/private-type-index.ttl'}, 'label': 'private'}, 'type': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'http://www.w3.org/2005/01/wf/flow#Tracker'}}, {'instance': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/publicStuff/actionItems.ttl#this'}, 'scope': {'agent': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/profile/card.ttl#it'}, 'index': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/profile/public-type-index.ttl'}, 'label': 'public'}, 'type': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'http://www.w3.org/2005/01/wf/flow#Tracker'}}, {'instance': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/project4/clubIssues.ttl#this'}, 'scope': {'agent': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/profile/card.ttl#it'}, 'index': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/profile/public-type-index.ttl'}, 'label': 'public'}, 'type': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'http://www.w3.org/2005/01/wf/flow#Tracker'}}, {'instance': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/privateStuff/ToDo.ttl#this'}, 'scope': {'agent': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/profile/card.ttl#it'}, 'index': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/settings/private-type-index.ttl'}, 'label': 'private'}, 'type': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'http://www.w3.org/2005/01/wf/flow#Tracker'}}, {'instance': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/privateStuff/Goals.ttl#this'}, 'scope': {'agent': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/profile/card.ttl#it'}, 'index': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/settings/private-type-index.ttl'}, 'label': 'private'}, 'type': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'http://www.w3.org/2005/01/wf/flow#Tracker'}}, {'instance': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/privateStuff/tasks.ttl#this'}, 'scope': {'agent': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/profile/card.ttl#it'}, 'index': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/settings/private-type-index.ttl'}, 'label': 'private'}, 'type': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'http://www.w3.org/2005/01/wf/flow#Tracker'}}]

0 commit comments

Comments
 (0)