Skip to content

Commit 6f340bf

Browse files
committed
Correct addnew and deleteexisting checks.
Count deleted statements and raise error if none deleted in cut. Check indexes against list in updateList.
1 parent c2fb0a2 commit 6f340bf

8 files changed

Lines changed: 223 additions & 138 deletions

File tree

lib/ld/patch/algebra/add.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,18 @@ def execute(queryable, options = {})
3737
case var
3838
when RDF::Query::Pattern
3939
s = var.bind(solution)
40+
# FIXME 400 Bad Request
4041
raise LD::Patch::Error, "Operand uses unbound pattern #{var.inspect}" if s.variable?
4142
s
4243
when RDF::Query::Variable
44+
# FIXME 400 Bad Request
4345
raise LD::Patch::Error, "Operand uses unbound variable #{var.inspect}" unless solution.bound?(var)
4446
solution[var]
4547
end
4648
end
4749

4850
# If `:new` is specified, verify that no triple in triples exists in queryable
49-
if options[:new]
51+
if @options[:new]
5052
triples.each do |triple|
5153
raise LD::Patch::Error, "Target graph contains added triple #{triple.to_ntriples}" if queryable.has_statement?(triple)
5254
end

lib/ld/patch/algebra/bind.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def execute(queryable, options = {})
7474

7575
# Bind variables to path
7676
if value.variable?
77+
# FIXME 400 Bad Request
7778
raise LD::Patch::Error, "Operand uses unbound variable #{value.inspect}" unless solution.bound?(value)
7879
value = solution[value]
7980
end

lib/ld/patch/algebra/cut.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,25 @@ def execute(queryable, options = {})
3232
var = operand(0)
3333

3434
# Bind variable
35+
# FIXME 400 Bad Request
3536
raise LD::Patch::Error, "Operand uses unbound variable #{var.inspect}" unless solution.bound?(var)
3637
var = solution[var]
3738

39+
cut_count = 0
3840
# Get triples to delete using consice bounded description
3941
queryable.concise_bounded_description(var) do |statement|
4042
queryable.delete(statement)
43+
cut_count += 1
4144
end
4245

4346
# Also delete triples having var in the object position
4447
queryable.query(object: var).each do |statement|
4548
queryable.delete(statement)
49+
cut_count += 1
4650
end
51+
52+
raise LD::Patch::Error, "Cut removed no triples" unless cut_count > 0
53+
4754
bindings
4855
end
4956
end

lib/ld/patch/algebra/delete.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,18 @@ def execute(queryable, options = {})
3737
case var
3838
when RDF::Query::Pattern
3939
s = var.bind(solution)
40+
# FIXME 400 Bad Request
4041
raise LD::Patch::Error, "Operand uses unbound pattern #{var.inspect}" if s.variable?
4142
s
4243
when RDF::Query::Variable
44+
# FIXME 400 Bad Request
4345
raise LD::Patch::Error, "Operand uses unbound variable #{var.inspect}" unless solution.bound?(var)
4446
solution[var]
4547
end
4648
end
4749

4850
# If `:new` is specified, verify that no triple in triples exists in queryable
49-
if options[:existing]
51+
if @options[:existing]
5052
triples.each do |triple|
5153
raise LD::Patch::Error, "Target graph does not contain triple #{triple.to_ntriples}" unless queryable.has_statement?(triple)
5254
end

lib/ld/patch/algebra/update_list.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def execute(queryable, options = {})
3131

3232
# Bind variables to path
3333
if var_or_iri.variable?
34+
# FIXME 400 Bad Request
3435
raise LD::Patch::Error, "Operand uses unbound variable #{var_or_iri.inspect}" unless solution.bound?(var_or_iri)
3536
var_or_iri = solution[variable]
3637
end
@@ -54,7 +55,13 @@ def execute(queryable, options = {})
5455
when slice2 < 0 then list.length + slice2.to_i
5556
else slice2.to_i
5657
end
58+
59+
# FIXME 400 Bad Request
60+
raise LD::Patch::Error, "UpdateList slice indexes out of order #{start}..#{finish}}" if finish < start
61+
5762
length = finish - start
63+
raise LD::Patch::Error, "UpdateList out of bounds #{start}..#{finish}}" if start + length > list.length
64+
raise LD::Patch::Error, "UpdateList out of bounds #{start}..#{finish}}" if start < 0
5865

5966
# Uses #[]= logic in RDF::List
6067
list[start, length] = collection

lib/ld/patch/parser.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ def iri(value)
573573
end
574574

575575
def ns(prefix, suffix)
576+
# FIXME 400 Bad Request
576577
error("pname", "undefined prefix #{prefix.inspect}") unless prefix(prefix)
577578
base = prefix(prefix).to_s
578579
suffix = suffix.to_s.sub(/^\#/, "") if base.index("#")

0 commit comments

Comments
 (0)