mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 15:31:15 -05:00
handle bom in phone number field
This commit is contained in:
@@ -105,24 +105,20 @@ def extract_phones(job):
|
|||||||
current_app.logger.info(f"HEADERS {first_row}")
|
current_app.logger.info(f"HEADERS {first_row}")
|
||||||
phone_index = 0
|
phone_index = 0
|
||||||
for item in first_row:
|
for item in first_row:
|
||||||
if item.lower() == "phone number":
|
# Note: may contain a BOM and look like \ufeffphone number
|
||||||
|
if "phone number" in item.lower():
|
||||||
break
|
break
|
||||||
phone_index = phone_index + 1
|
phone_index = phone_index + 1
|
||||||
|
|
||||||
phones = {}
|
phones = {}
|
||||||
job_row = 0
|
job_row = 0
|
||||||
for row in job:
|
for row in job:
|
||||||
row = row.split(",")
|
row = row.split(",")
|
||||||
# TODO WHY ARE WE CALCULATING PHONE INDEX IN THE LOOP?
|
|
||||||
phone_index = 0
|
|
||||||
for item in first_row:
|
|
||||||
if item.lower() == "phone number":
|
|
||||||
break
|
|
||||||
phone_index = phone_index + 1
|
|
||||||
current_app.logger.info(f"PHONE INDEX IS NOW {phone_index}")
|
current_app.logger.info(f"PHONE INDEX IS NOW {phone_index}")
|
||||||
current_app.logger.info(f"LENGTH OF ROW IS {len(row)}")
|
current_app.logger.info(f"LENGTH OF ROW IS {len(row)}")
|
||||||
if phone_index >= len(row):
|
if phone_index >= len(row):
|
||||||
phones[job_row] = "Error: can't retrieve phone number"
|
phones[job_row] = "Error: can't retrieve phone number"
|
||||||
current_app.logger.error("Corrupt csv file, missing columns job_id {job_id} service_id {service_id}")
|
current_app.logger.error("Corrupt csv file")
|
||||||
else:
|
else:
|
||||||
my_phone = row[phone_index]
|
my_phone = row[phone_index]
|
||||||
my_phone = re.sub(r"[\+\s\(\)\-\.]*", "", my_phone)
|
my_phone = re.sub(r"[\+\s\(\)\-\.]*", "", my_phone)
|
||||||
|
|||||||
@@ -67,6 +67,13 @@ def test_get_s3_file_makes_correct_call(notify_api, mocker):
|
|||||||
0,
|
0,
|
||||||
"15553333333",
|
"15553333333",
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
# simulate file saved with utf8withbom
|
||||||
|
"\\ufeffPHONE NUMBER,Name\r\n5555555550,T 1\r\n5555555551,T 5,3/31/2024\r\n5555555552,T 2",
|
||||||
|
"eee",
|
||||||
|
2,
|
||||||
|
"5555555552",
|
||||||
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_get_phone_number_from_s3(
|
def test_get_phone_number_from_s3(
|
||||||
|
|||||||
Reference in New Issue
Block a user