summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Schneider2017-01-08 16:52:29 +0100
committerSven Schneider2017-01-08 16:52:29 +0100
commit7a9248c50011d9a3a86514637355732e30f13bc1 (patch)
treec8afc0a3560c3abaff4a3b55e0937ad2f50cfd72
parente48b2467e7307e78a45f0d6f5ac555d6252eca63 (diff)
downloadaur-7a9248c50011d9a3a86514637355732e30f13bc1.tar.gz
add fix for bug in remote context handling
-rw-r--r--.SRCINFO6
-rw-r--r--0001-Fixed-remote-frame-context-handling.patch253
-rw-r--r--PKGBUILD10
3 files changed, 264 insertions, 5 deletions
diff --git a/.SRCINFO b/.SRCINFO
index 56a821d5f06..da9906ec3f9 100644
--- a/.SRCINFO
+++ b/.SRCINFO
@@ -1,16 +1,18 @@
# Generated by mksrcinfo v8
-# Wed Dec 28 12:10:29 UTC 2016
+# Sun Jan 8 15:51:49 UTC 2017
pkgbase = python-pyld
pkgdesc = An implementation of the JSON-LD specification in Python
pkgver = 0.7.1
- pkgrel = 1
+ pkgrel = 2
url = https://github.com/digitalbazaar/pyld
arch = any
license = BSD
makedepends = python-setuptools
makedepends = python2-setuptools
source = https://github.com/digitalbazaar/pyld/archive/0.7.1.tar.gz
+ source = 0001-Fixed-remote-frame-context-handling.patch
sha512sums = 1db8aa6523183df5b427580e2b2504c871769c2c7c4612f3b93b7509651f4fd0fb17a0d0ccf251135b908648e32b256d2de9e118161586393ad332c7d8ad4cad
+ sha512sums = d0b15814c2fe315ad3dddda8ea452229a172be060d7074b6d99ec9eaed857f2e6b715e760cbcc194f9c8a679bc929ac652df847377c6e8b4944bf77795432f19
pkgname = python-pyld
depends = python-setuptools
diff --git a/0001-Fixed-remote-frame-context-handling.patch b/0001-Fixed-remote-frame-context-handling.patch
new file mode 100644
index 00000000000..e5368df3e8b
--- /dev/null
+++ b/0001-Fixed-remote-frame-context-handling.patch
@@ -0,0 +1,253 @@
+From a87843cca026e82fe2779d7176c6be3a6e4c9478 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?=C5=81ukasz=20Jancewicz?= <lj@rdprojekt.pl>
+Date: Thu, 24 Jul 2014 16:11:10 +0200
+Subject: [PATCH 1/2] Fixed remote frame context handling.
+
+Added unit-tests to cover this scenario.
+---
+ lib/pyld/jsonld.py | 9 ++-
+ tests/unit-tests.py | 202 ++++++++++++++++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 206 insertions(+), 5 deletions(-)
+ create mode 100644 tests/unit-tests.py
+
+diff --git a/lib/pyld/jsonld.py b/lib/pyld/jsonld.py
+index b9eecaa..0aa8ef1 100644
+--- a/lib/pyld/jsonld.py
++++ b/lib/pyld/jsonld.py
+@@ -832,11 +832,11 @@ class JsonLdProcessor:
+ if frame is not None:
+ ctx = frame.get('@context', {})
+ if remote_frame['contextUrl'] is not None:
+- if ctx is not None:
+- ctx = remote_frame['contextUrl']
+- else:
++ if ctx:
+ ctx = JsonLdProcessor.arrayify(ctx)
+ ctx.append(remote_frame['contextUrl'])
++ else:
++ ctx = remote_frame['contextUrl']
+ frame['@context'] = ctx
+
+ try:
+@@ -1036,8 +1036,7 @@ class JsonLdProcessor:
+
+ # retrieve URLs in local_ctx
+ local_ctx = copy.deepcopy(local_ctx)
+- if (_is_string(local_ctx) or (
+- _is_object(local_ctx) and '@context' not in local_ctx)):
++ if not (_is_object(local_ctx) and '@context' in local_ctx):
+ local_ctx = {'@context': local_ctx}
+ try:
+ self._retrieve_context_urls(
+diff --git a/tests/unit-tests.py b/tests/unit-tests.py
+new file mode 100644
+index 0000000..3248b20
+--- /dev/null
++++ b/tests/unit-tests.py
+@@ -0,0 +1,202 @@
++import json
++import unittest
++
++from pyld import jsonld
++
++# Inputs and outputs used here are essentially modified documents
++# of JSON-LD frame-0001 test.
++
++FRAME_0001_IN = '''{
++ "@context": {
++ "dc": "http://purl.org/dc/elements/1.1/",
++ "ex": "http://example.org/vocab#",
++ "ex:contains": {"@type": "@id"}
++ },
++ "@graph": [
++ {
++ "@id": "http://example.org/test/#library",
++ "@type": "ex:Library",
++ "ex:contains": "http://example.org/test#book"
++ },
++ {
++ "@id": "http://example.org/test#book",
++ "@type": "ex:Book",
++ "dc:contributor": "Writer",
++ "dc:title": "My Book",
++ "ex:contains": "http://example.org/test#chapter"
++ },
++ {
++ "@id": "http://example.org/test#chapter",
++ "@type": "ex:Chapter",
++ "dc:description": "Fun",
++ "dc:title": "Chapter One"
++ }
++ ]
++}'''
++
++
++FRAME_0001_FRAME = '''{
++ "@context": {
++ "dc": "http://purl.org/dc/elements/1.1/",
++ "ex": "http://example.org/vocab#"
++ },
++ "@type": "ex:Library",
++ "ex:contains": {
++ "@type": "ex:Book",
++ "ex:contains": {
++ "@type": "ex:Chapter"
++ }
++ }
++}'''
++
++FRAME_0001_FRAME_WITHOUT_CONTEXT = '''{
++ "@type": "ex:Library",
++ "ex:contains": {
++ "@type": "ex:Book",
++ "ex:contains": {
++ "@type": "ex:Chapter"
++ }
++ }
++}'''
++
++FRAME_0001_FRAME_WITH_PARTIAL_CONTEXT = '''{
++ "@context": {
++ "dc": "http://purl.org/dc/elements/1.1/"
++ },
++ "@type": "ex:Library",
++ "ex:contains": {
++ "@type": "ex:Book",
++ "ex:contains": {
++ "@type": "ex:Chapter"
++ }
++ }
++}'''
++
++FRAME_0001_FRAME_CONTEXT = '''{
++ "@context": {
++ "dc": "http://purl.org/dc/elements/1.1/",
++ "ex": "http://example.org/vocab#"
++ }
++}'''
++
++FRAME_0001_FRAME_PARTIAL_CONTEXT = '''{
++ "@context": {
++ "ex": "http://example.org/vocab#"
++ }
++}'''
++
++FRAME_0001_OUT_WITH_REMOTE_CONTEXT = '''{
++ "@context": "http://example.com/frame-context.json",
++ "@graph": [{
++ "@id": "http://example.org/test/#library",
++ "@type": "ex:Library",
++ "ex:contains": {
++ "@id": "http://example.org/test#book",
++ "@type": "ex:Book",
++ "dc:contributor": "Writer",
++ "dc:title": "My Book",
++ "ex:contains": {
++ "@id": "http://example.org/test#chapter",
++ "@type": "ex:Chapter",
++ "dc:description": "Fun",
++ "dc:title": "Chapter One"
++ }
++ }
++ }]
++}'''
++
++FRAME_0001_OUT_WITH_LOCAL_AND_REMOTE_CONTEXT = '''{
++ "@context": [{
++ "dc": "http://purl.org/dc/elements/1.1/",
++ "ex": "http://example.org/vocab#"
++ }, "http://example.com/frame-context.json"],
++ "@graph": [{
++ "@id": "http://example.org/test/#library",
++ "@type": "ex:Library",
++ "ex:contains": {
++ "@id": "http://example.org/test#book",
++ "@type": "ex:Book",
++ "dc:contributor": "Writer",
++ "dc:title": "My Book",
++ "ex:contains": {
++ "@id": "http://example.org/test#chapter",
++ "@type": "ex:Chapter",
++ "dc:description": "Fun",
++ "dc:title": "Chapter One"
++ }
++ }
++ }]
++}'''
++
++FRAME_0001_OUT_WITH_HALF_LOCAL_AND_HALF_REMOTE_CONTEXT = '''{
++ "@context": [{
++ "dc": "http://purl.org/dc/elements/1.1/"
++ }, "http://example.com/frame-context.json"],
++ "@graph": [{
++ "@id": "http://example.org/test/#library",
++ "@type": "ex:Library",
++ "ex:contains": {
++ "@id": "http://example.org/test#book",
++ "@type": "ex:Book",
++ "dc:contributor": "Writer",
++ "dc:title": "My Book",
++ "ex:contains": {
++ "@id": "http://example.org/test#chapter",
++ "@type": "ex:Chapter",
++ "dc:description": "Fun",
++ "dc:title": "Chapter One"
++ }
++ }
++ }]
++}'''
++
++
++class TestCaseForFrame(unittest.TestCase):
++
++ def _test_remote_context_with(
++ self, frame_doc, frame_context_doc, out_doc):
++ input_ = json.loads(FRAME_0001_IN)
++
++ def fake_loader(url):
++ if url == 'http://example.com/frame.json':
++ return {
++ 'contextUrl': 'http://example.com/frame-context.json',
++ 'document': frame_doc,
++ 'documentUrl': url
++ }
++ elif url == 'http://example.com/frame-context.json':
++ return {
++ 'contextUrl': None,
++ 'document': frame_context_doc,
++ 'documentUrl': url
++ }
++ else:
++ raise Exception("Unknown URL: {}".format(url))
++
++ options = {
++ 'documentLoader': fake_loader
++ }
++ framed = jsonld.frame(
++ input_, 'http://example.com/frame.json', options=options)
++
++ self.assertEqual(framed, json.loads(out_doc))
++
++ def test_remote_context_local_and_remote_context_equal(self):
++ self._test_remote_context_with(
++ FRAME_0001_FRAME, FRAME_0001_FRAME_CONTEXT,
++ FRAME_0001_OUT_WITH_LOCAL_AND_REMOTE_CONTEXT)
++
++ def test_remote_context_remote_context_only(self):
++ self._test_remote_context_with(
++ FRAME_0001_FRAME_WITHOUT_CONTEXT, FRAME_0001_FRAME_CONTEXT,
++ FRAME_0001_OUT_WITH_REMOTE_CONTEXT)
++
++ def test_remote_context_half_context_local_and_half_remote(self):
++ self._test_remote_context_with(
++ FRAME_0001_FRAME_WITH_PARTIAL_CONTEXT,
++ FRAME_0001_FRAME_PARTIAL_CONTEXT,
++ FRAME_0001_OUT_WITH_HALF_LOCAL_AND_HALF_REMOTE_CONTEXT)
++
++
++if __name__ == '__main__':
++ unittest.main()
+\ No newline at end of file
+--
+2.11.0
+
diff --git a/PKGBUILD b/PKGBUILD
index ddf5b865565..e8cb0ff4cba 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -3,16 +3,20 @@
pkgname=('python-pyld' 'python2-pyld')
_pkgname='pyld'
pkgver=0.7.1
-pkgrel=1
+pkgrel=2
pkgdesc="An implementation of the JSON-LD specification in Python"
arch=('any')
url="https://github.com/digitalbazaar/pyld"
license=('BSD')
makedepends=('python-setuptools' 'python2-setuptools')
-source=(https://github.com/digitalbazaar/${_pkgname}/archive/${pkgver}.tar.gz)
-sha512sums=('1db8aa6523183df5b427580e2b2504c871769c2c7c4612f3b93b7509651f4fd0fb17a0d0ccf251135b908648e32b256d2de9e118161586393ad332c7d8ad4cad')
+source=(https://github.com/digitalbazaar/${_pkgname}/archive/${pkgver}.tar.gz
+ 0001-Fixed-remote-frame-context-handling.patch)
+sha512sums=('1db8aa6523183df5b427580e2b2504c871769c2c7c4612f3b93b7509651f4fd0fb17a0d0ccf251135b908648e32b256d2de9e118161586393ad332c7d8ad4cad'
+ 'd0b15814c2fe315ad3dddda8ea452229a172be060d7074b6d99ec9eaed857f2e6b715e760cbcc194f9c8a679bc929ac652df847377c6e8b4944bf77795432f19')
prepare() {
+ patch -p1 -d "${srcdir}/${_pkgname}-${pkgver}" < "${srcdir}"/0001-Fixed-remote-frame-context-handling.patch
+
cp -a "${_pkgname}-${pkgver}" "${_pkgname}-${pkgver}-py2"
}