Skip to content

Commit 91587b9

Browse files
authored
Merge pull request #63 from wijatplay3/master
feat: add support for SafeMode on expandObject
2 parents 9932c26 + c615a3e commit 91587b9

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

ld/api_expand.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,11 @@ func (api *JsonLdApi) expandObject(activeCtx *Context, activeProperty string, ex
359359
var expandedValue interface{}
360360
// 7.3)
361361
if expandedProperty == "" || (!strings.Contains(expandedProperty, ":") && !IsKeyword(expandedProperty)) {
362-
continue
362+
if activeCtx.options != nil && activeCtx.options.SafeMode {
363+
return NewJsonLdError(InvalidProperty, "Dropping property that did not expand into an absolute IRI or keyword.")
364+
} else {
365+
continue
366+
}
363367
}
364368
// 7.4)
365369
if IsKeyword(expandedProperty) {

ld/errors.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,14 @@ const (
7878
IRIConfusedWithPrefix ErrorCode = "IRI confused with prefix"
7979

8080
// non spec related errors
81-
SyntaxError ErrorCode = "syntax error"
82-
NotImplemented ErrorCode = "not implemented"
83-
UnknownFormat ErrorCode = "unknown format"
84-
InvalidInput ErrorCode = "invalid input"
85-
ParseError ErrorCode = "parse error"
86-
IOError ErrorCode = "io error"
87-
UnknownError ErrorCode = "unknown error"
81+
SyntaxError ErrorCode = "syntax error"
82+
NotImplemented ErrorCode = "not implemented"
83+
UnknownFormat ErrorCode = "unknown format"
84+
InvalidInput ErrorCode = "invalid input"
85+
ParseError ErrorCode = "parse error"
86+
IOError ErrorCode = "io error"
87+
InvalidProperty ErrorCode = "invalid property"
88+
UnknownError ErrorCode = "unknown error"
8889
)
8990

9091
func (e JsonLdError) Error() string {

ld/options.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ type JsonLdOptions struct { //nolint:stylecheck
6565
Algorithm string
6666
UseNamespaces bool
6767
OutputForm string
68+
SafeMode bool
6869
}
6970

7071
// NewJsonLdOptions creates and returns new instance of JsonLdOptions with the given base.
@@ -88,6 +89,7 @@ func NewJsonLdOptions(base string) *JsonLdOptions { //nolint:stylecheck
8889
Algorithm: AlgorithmURGNA2012,
8990
UseNamespaces: false,
9091
OutputForm: "",
92+
SafeMode: false,
9193
}
9294
}
9395

0 commit comments

Comments
 (0)