Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
a792420e
Unverified
Commit
a792420e
authored
Aug 19, 2019
by
Robert Knight
Committed by
GitHub
Aug 19, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1307 from hypothesis/error-when-searching2
Fix JS error when searching after creating a page draft
parents
70716a34
d35a71d4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
8 deletions
+71
-8
view-filter-test.js
src/sidebar/services/test/view-filter-test.js
+64
-4
view-filter.js
src/sidebar/services/view-filter.js
+7
-4
No files found.
src/sidebar/services/test/view-filter-test.js
View file @
a792420e
...
...
@@ -74,9 +74,10 @@ describe('sidebar/services/view-filter', () => {
describe
(
'"any" field'
,
()
=>
{
it
(
'finds matches in any field'
,
()
=>
{
const
annotations
=
[
{
id
:
1
,
text
:
poem
.
tiger
},
{
id
:
2
,
user
:
'Tiger'
},
{
id
:
3
,
tags
:
[
'Tiger'
]
},
{
id
:
1
,
text
:
poem
.
tiger
,
target
:
[{}]
},
{
id
:
4
,
user
:
'lion'
,
target
:
[{}]
},
{
id
:
2
,
user
:
'Tiger'
,
target
:
[{}]
},
{
id
:
3
,
tags
:
[
'Tiger'
],
target
:
[{}]
},
];
const
filters
=
{
any
:
{
terms
:
[
'Tiger'
],
operator
:
'and'
}
};
...
...
@@ -191,6 +192,7 @@ describe('sidebar/services/view-filter', () => {
const
annotation
=
{
id
:
1
,
updated
:
isoDateWithAge
(
50
),
target
:
[{}],
};
const
filters
=
{
since
:
{
terms
:
[
100
],
operator
:
'and'
},
...
...
@@ -205,6 +207,7 @@ describe('sidebar/services/view-filter', () => {
const
annotation
=
{
id
:
1
,
updated
:
isoDateWithAge
(
150
),
target
:
[{}],
};
const
filters
=
{
since
:
{
terms
:
[
100
],
operator
:
'and'
},
...
...
@@ -217,7 +220,11 @@ describe('sidebar/services/view-filter', () => {
});
it
(
'ignores filters with no terms in the query'
,
()
=>
{
const
annotation
=
{
id
:
1
,
tags
:
[
'foo'
]
};
const
annotation
=
{
id
:
1
,
tags
:
[
'foo'
],
target
:
[{}],
};
const
filters
=
{
any
:
{
terms
:
[
'foo'
],
...
...
@@ -233,4 +240,57 @@ describe('sidebar/services/view-filter', () => {
assert
.
deepEqual
(
result
,
[
1
]);
});
it
(
'ignores annotations (drafts) with no id'
,
()
=>
{
const
annotation
=
{
tags
:
[
'foo'
],
target
:
[{}],
};
const
filters
=
{
any
:
{
terms
:
[
'foo'
],
operator
:
'and'
,
},
};
const
result
=
viewFilter
.
filter
([
annotation
],
filters
);
assert
.
deepEqual
(
result
,
[]);
});
describe
(
'malformed target object'
,
()
=>
{
it
(
'should not fail on annotations without a target object'
,
()
=>
{
const
annotation
=
{
id
:
1
,
text
:
'foo'
,
// Missing target
};
const
filters
=
{
any
:
{
terms
:
[
'foo'
],
operator
:
'or'
,
},
};
viewFilter
.
filter
([
annotation
],
filters
);
});
it
(
'should not fail on annotations without a target object item'
,
()
=>
{
const
annotation
=
{
id
:
1
,
text
:
'foo'
,
target
:
[],
// Missing target item
};
const
filters
=
{
any
:
{
terms
:
[
'foo'
],
operator
:
'or'
,
},
};
viewFilter
.
filter
([
annotation
],
filters
);
});
});
});
src/sidebar/services/view-filter.js
View file @
a792420e
...
...
@@ -100,9 +100,10 @@ function viewFilter(unicode) {
quote
:
{
autofalse
:
ann
=>
(
ann
.
references
||
[]).
length
>
0
,
value
(
annotation
)
{
if
(
!
annotation
.
target
)
{
// FIXME: All annotations *must* have a target, so this check should
// not be required.
if
(
!
annotation
.
target
||
!
annotation
.
target
.
length
)
{
// Sanity check that ignores any annotation without a target. We should
// never arrive at this place in the code, but its a safe guard against
// anything from the server that may be malformed.
return
''
;
}
const
target
=
annotation
.
target
[
0
];
...
...
@@ -183,7 +184,9 @@ function viewFilter(unicode) {
const
rootFilter
=
new
BinaryOpFilter
(
'and'
,
fieldFilters
);
return
annotations
.
filter
(
ann
=>
rootFilter
.
matches
(
ann
))
.
filter
(
ann
=>
{
return
ann
.
id
&&
rootFilter
.
matches
(
ann
);
})
.
map
(
ann
=>
ann
.
id
);
};
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment