Skip to content

Commit

Permalink
Fix duplicate URL encoding and missing parameter on getCoordinates call
Browse files Browse the repository at this point in the history
Fix wrong year and add clarification to regex call on getAddress
  • Loading branch information
kcmcg committed Feb 17, 2023
1 parent 198a018 commit 534df5b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions CensusExternalModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ function downloadCensusData() {
var address = $('[name=\"".$addressField."\"]').val();
if (address) {
var encodedAddress = address.replace(/\s+/g, '+');
encodedAddress = encodedAddress.replace(/United States/g, '+');
var encodedAddress = address.replace(/United States/g, '');
console.log('Looking up '+encodedAddress);
$.post('".$this->getUrl('getAddress.php')."', { 'get':1,'address':encodedAddress, 'year': year}, function(json) {
console.log('Got data from TigerWeb');
Expand Down Expand Up @@ -125,6 +124,7 @@ function downloadCensusDataFromLatLong() {
{
url:'".$this->getUrl('getCoordinates.php')."',
data:{
get: 1,
lat: latitude,
long: longitude,
year: year
Expand Down
6 changes: 4 additions & 2 deletions getAddress.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

if ($_POST['get']) {
$address = url_encode(preg_replace("/[^a-zA-Z0-9 ,]/","",$_POST['address']));
## Remove any characters that aren't a-z, 0-9, " ", or "," from the address string to prevent
## sending any malformed requests
$address = urlencode(preg_replace("/[^a-zA-Z0-9 ,]/","",$_POST['address']));
$year = $_POST['year'];
$url = 'https://geocoding.geo.census.gov/geocoder/geographies/onelineaddress?address='.$address.'&'.$module->getSharedArgs($census['year']);
$url = 'https://geocoding.geo.census.gov/geocoder/geographies/onelineaddress?address='.$address.'&'.$module->getSharedArgs($year);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
Expand Down

0 comments on commit 534df5b

Please sign in to comment.