Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: encodeURIComponent path params (#1087)
- Loading branch information
1 parent
a269cab
commit d89a735
Showing
5 changed files
with
119 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2016, Google, Inc. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
const {google} = require('googleapis'); | ||
const sampleClient = require('../sampleclient'); | ||
|
||
const webmasters = google.webmasters({ | ||
version: 'v3', | ||
auth: sampleClient.oAuth2Client | ||
}); | ||
|
||
function runSample (callback) { | ||
webmasters.searchanalytics.query({ | ||
siteUrl: 'http://jbeckwith.com', | ||
resource: { | ||
startDate: '2018-01-01', | ||
endDate: '2018-04-01' | ||
} | ||
}, (err, res) => { | ||
if (err) { | ||
console.error(err); | ||
throw err; | ||
} | ||
console.log(res.data); | ||
callback(res.data); | ||
}); | ||
} | ||
|
||
if (module === require.main) { | ||
const scopes = [ | ||
'https://www.googleapis.com/auth/webmasters', | ||
'https://www.googleapis.com/auth/webmasters.readonly' | ||
]; | ||
sampleClient.authenticate(scopes, err => { | ||
if (err) { | ||
throw err; | ||
} | ||
runSample(() => { /* complete */ }); | ||
}); | ||
} | ||
|
||
module.exports = { | ||
runSample, | ||
client: sampleClient.oAuth2Client | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2018, Google, LLC. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import * as assert from 'assert'; | ||
import * as nock from 'nock'; | ||
import {Utils} from './../utils'; | ||
|
||
nock.disableNetConnect(); | ||
|
||
// tslint:disable: no-any | ||
const samples: any = { | ||
query: require('../../../samples/webmasters/query') | ||
}; | ||
|
||
for (const p in samples) { | ||
if (samples[p]) { | ||
samples[p].client.credentials = {access_token: 'not-a-token'}; | ||
} | ||
} | ||
|
||
describe('webmaster samples', () => { | ||
afterEach(() => { | ||
nock.cleanAll(); | ||
}); | ||
|
||
it('should query analytics', done => { | ||
const siteUrl = 'http://jbeckwith.com'; | ||
const path = `/webmasters/v3/sites/${ | ||
encodeURIComponent(siteUrl)}/searchAnalytics/query`; | ||
const scope = nock(Utils.baseUrl).post(path).reply(200, {}); | ||
samples.query.runSample((data: {}) => { | ||
assert(data); | ||
scope.done(); | ||
done(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d89a735
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks several api endpoints who's params include '/' characters.
See #1099