From 15e4451d8fdece3cc1bd7ea58a8f7d90bbb2a23e Mon Sep 17 00:00:00 2001
From: Dan Nicholson <nicholson@endlessm.com>
Date: Mon, 10 Feb 2020 09:35:49 -0700
Subject: [PATCH] Use urlencode to construct query parameters

Including the `?` and `&` in the templates is awkward. Instead, use a
dictionary with just the parameter names and use `urlencode` to
construct the query string. This also has the advantage that any values
will be properly HTML encoded.

https://phabricator.endlessm.com/T29306
---
 update_repos | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/update_repos b/update_repos
index b370220..717e4f4 100755
--- a/update_repos
+++ b/update_repos
@@ -7,6 +7,7 @@ import argparse
 from collections import namedtuple
 from subprocess import Popen, PIPE
 
+from urllib import urlencode
 from urllib2 import urlopen
 import json
 from urlparse import urlparse
@@ -15,8 +16,9 @@ WHITELIST=[]
 BLACKLIST=[]
 
 LISTINGS_PER_PAGE = 100
-ACCESS_TOKEN_PARAM = '?access_token=%s'
-LISTING_PAGE_PARAM = '&per_page=%d&page=%d'
+ACCESS_TOKEN_PARAM = 'access_token'
+LISTINGS_PER_PAGE_PARAM = 'per_page'
+LISTING_PAGE_PARAM = 'page'
 GITHUB_API_HOST = 'https://api.github.com'
 
 GIT_CLONE_CMD = 'git clone %s %s %s'
@@ -73,7 +75,12 @@ class AttributeDict(dict):
         self[attr] = value
 
 def read_api_uri(uri, config, page=1):
-    uri += ACCESS_TOKEN_PARAM % config.token + LISTING_PAGE_PARAM % (LISTINGS_PER_PAGE, page)
+    params = {
+        ACCESS_TOKEN_PARAM: config.token,
+        LISTINGS_PER_PAGE_PARAM: LISTINGS_PER_PAGE,
+        LISTING_PAGE_PARAM: page,
+    }
+    uri += '?' + urlencode(params)
 
     if config.debug:
         print "Trying:", uri
-- 
GitLab