Skip to content

Commit b7d5fce

Browse files
committed
chats: make sure message data is only read from message document
1 parent 53aacc2 commit b7d5fce

2 files changed

Lines changed: 115 additions & 0 deletions

File tree

chats/rdflib/src/module/queries/MessageQuery.spec.ts

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,43 @@ describe(MessageQuery.name, () => {
7070
expect(result).toEqual(null);
7171
});
7272

73+
it("that only have content in a wrong document", () => {
74+
const store = graph();
75+
parse(
76+
`
77+
@prefix : <#>.
78+
@prefix sioc: <http://rdfs.org/sioc/ns#>.
79+
@prefix dct: <http://purl.org/dc/terms/>.
80+
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
81+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
82+
83+
:1
84+
dct:created "2024-07-01T17:47:14Z"^^xsd:dateTime ;
85+
foaf:maker <https://pod.test/alice/profile/card#me> ;
86+
.
87+
88+
`,
89+
store,
90+
"https://pod.test/message",
91+
);
92+
93+
parse(
94+
`
95+
@prefix sioc: <http://rdfs.org/sioc/ns#>.
96+
97+
<message#1>
98+
sioc:content "wrong content" .
99+
`,
100+
store,
101+
"https://pod.test/wrong",
102+
);
103+
const result = new MessageQuery(
104+
sym("https://pod.test/message#1"),
105+
store,
106+
).queryMessage();
107+
expect(result).toEqual(null);
108+
});
109+
73110
it("that have no date", () => {
74111
const store = graph();
75112
parse(
@@ -95,6 +132,42 @@ describe(MessageQuery.name, () => {
95132
expect(result).toEqual(null);
96133
});
97134

135+
it("that only have a date in the wrong document", () => {
136+
const store = graph();
137+
parse(
138+
`
139+
@prefix : <#>.
140+
@prefix sioc: <http://rdfs.org/sioc/ns#>.
141+
@prefix dct: <http://purl.org/dc/terms/>.
142+
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
143+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
144+
145+
:1 sioc:content "A message" ;
146+
foaf:maker <https://pod.test/alice/profile/card#me> ;
147+
.
148+
149+
`,
150+
store,
151+
"https://pod.test/message",
152+
);
153+
parse(
154+
`
155+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
156+
@prefix dct: <http://purl.org/dc/terms/>.
157+
158+
<message#1>
159+
dct:created "2024-01-02"^^xsd:dateTime .
160+
`,
161+
store,
162+
"https://pod.test/wrong",
163+
);
164+
const result = new MessageQuery(
165+
sym("https://pod.test/message#1"),
166+
store,
167+
).queryMessage();
168+
expect(result).toEqual(null);
169+
});
170+
98171
it("that have no author", () => {
99172
const store = graph();
100173
parse(
@@ -119,6 +192,42 @@ describe(MessageQuery.name, () => {
119192
).queryMessage();
120193
expect(result).toEqual(null);
121194
});
195+
196+
it("that only have an author in the wrong document", () => {
197+
const store = graph();
198+
parse(
199+
`
200+
@prefix : <#>.
201+
@prefix sioc: <http://rdfs.org/sioc/ns#>.
202+
@prefix dct: <http://purl.org/dc/terms/>.
203+
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
204+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
205+
206+
:1 sioc:content "A message" ;
207+
dct:created "2024-07-01T17:47:14Z"^^xsd:dateTime ;
208+
.
209+
210+
`,
211+
store,
212+
"https://pod.test/message",
213+
);
214+
215+
parse(
216+
`
217+
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
218+
219+
<message#1>
220+
foaf:maker <https://pod.test/fake/profile/card#me> .
221+
`,
222+
store,
223+
"https://pod.test/wrong",
224+
);
225+
const result = new MessageQuery(
226+
sym("https://pod.test/message#1"),
227+
store,
228+
).queryMessage();
229+
expect(result).toEqual(null);
230+
});
122231
});
123232
});
124233
});

chats/rdflib/src/module/queries/MessageQuery.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export class MessageQuery {
1111
const text = this.store.anyValue(
1212
this.messageNode,
1313
sym("http://rdfs.org/sioc/ns#content"),
14+
undefined,
15+
this.messageNode.doc(),
1416
);
1517

1618
if (!text) {
@@ -20,11 +22,15 @@ export class MessageQuery {
2022
const date = this.store.anyJS(
2123
this.messageNode,
2224
sym("http://purl.org/dc/terms/created"),
25+
undefined,
26+
this.messageNode.doc(),
2327
);
2428
if (!date) return null;
2529
const authorWebId = this.store.anyValue(
2630
this.messageNode,
2731
sym("http://xmlns.com/foaf/0.1/maker"),
32+
undefined,
33+
this.messageNode.doc(),
2834
);
2935
if (!authorWebId) {
3036
return null;

0 commit comments

Comments
 (0)