Skip to content

Commit

Permalink
Merge pull request #502 from ooni/master+hotfix
Browse files Browse the repository at this point in the history
Make it harder to find AS0 measurements (+merge fix into master)
  • Loading branch information
bassosimone committed Oct 7, 2020
2 parents e22dc38 + 445812d commit d698422
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
17 changes: 11 additions & 6 deletions components/search/FilterSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,21 @@ class FilterSidebar extends React.Component {
switch(filterName) {
case 'asnFilter':
var asnValue = e.target.value
var asnRegEx = /^(^AS|as)?[0-9]+$/
if (asnValue && asnValue.match(asnRegEx) === null) {
// Accepts only formats like AS1234 or 1234
// https://regex101.com/r/DnkspD/latest
var asnRegEx = /^(AS)?([1-9][0-9]*)$/
if (
typeof asnValue === 'string' &&
(asnValue === '' || asnValue.match(asnRegEx) !== null)
) {
this.setState({
asnError: intl.formatMessage({id: 'Search.Sidebar.ASN.Error'}),
isFilterDirty: false
asnError: false,
isFilterDirty: true
})
} else {
this.setState({
asnError: false,
isFilterDirty: true
asnError: intl.formatMessage({id: 'Search.Sidebar.ASN.Error'}),
isFilterDirty: false
})
}
break
Expand Down
10 changes: 7 additions & 3 deletions pages/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,12 @@ class Search extends React.Component {
}

const measurements = msmtR.data
// drop results with probe_asn === 'AS0'
const results = measurements.results.filter(item => item.probe_asn !== 'AS0')

return {
error: null,
results: measurements.results,
results,
nextURL: measurements.metadata.next_url,
testNamesKeyed,
testNames,
Expand Down Expand Up @@ -240,8 +242,9 @@ class Search extends React.Component {
axios.get(this.state.nextURL)
.then((res) => {
// XXX update the query
const nextPageResults = res.data.results.filter(item => item.probe_asn !== 'AS0')
this.setState({
results: this.state.results.concat(res.data.results),
results: this.state.results.concat(nextPageResults),
nextURL: res.data.metadata.next_url,
show: this.state.show + 50
})
Expand All @@ -268,9 +271,10 @@ class Search extends React.Component {
// XXX do error handling
getMeasurements(query)
.then((res) => {
const results = res.data.results.filter(item => item.probe_asn !== 'AS0')
this.setState({
loading: false,
results: res.data.results,
results,
nextURL: res.data.metadata.next_url
})
})
Expand Down

0 comments on commit d698422

Please sign in to comment.