Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade deps, support for percent-coded form ids #20

Merged
merged 2 commits into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM python:3.8-alpine
FROM python:3.9-alpine

COPY requirements.txt /tmp/
RUN pip install --requirement /tmp/requirements.txt

RUN apk --update add openjdk8-jre-base
RUN apk --update add openjdk11-jre-headless

COPY ./app /app
WORKDIR /app
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pyxform-http is a Flask-based web service that uses pyxform to convert a XLSForm

# Install requirements
* Python 3
* Java
* Java 11

# Run locally
```
Expand Down Expand Up @@ -47,4 +47,9 @@ curl --request POST --header "X-XlsForm-FormId-Fallback: external-choices" --dat
A form that converts successfully (with no id)
```
curl --request POST --data-binary @test/pyxform-clean.xlsx http://127.0.0.1:5000/api/v1/convert
```

A form that converts successfully (with percent encoded id)
```
curl --request POST --header "X-XlsForm-FormId-Fallback: example%40example.org" --data-binary @test/pyxform-clean.xlsx http://127.0.0.1:5000/api/v1/convert
```
10 changes: 6 additions & 4 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from flask import Flask, jsonify, request, escape
from pyxform import xls2xform
from uuid import uuid4 as uuid
from urllib.parse import unquote


def app():
Expand All @@ -23,9 +24,10 @@ def post():
xlsform_formid_fallback_header = request.headers.get(
"X-XlsForm-FormId-Fallback"
)
xlsform_formid_fallback = str(uuid())
if xlsform_formid_fallback_header != None:
if xlsform_formid_fallback_header is not None:
xlsform_formid_fallback = sanitize(xlsform_formid_fallback_header)
else:
xlsform_formid_fallback = str(uuid())

with TemporaryDirectory() as temp_dir_name:
try:
Expand Down Expand Up @@ -74,7 +76,7 @@ def post():


def sanitize(string):
return os.path.basename(escape(string))
return os.path.basename(escape(unquote(string)))


def response(status=400, result=None, itemsets=None, warnings=None, error=None):
Expand All @@ -84,7 +86,7 @@ def response(status=400, result=None, itemsets=None, warnings=None, error=None):
result=result,
itemsets=itemsets,
warnings=warnings,
error=error,
error=error
),
status,
)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Flask==1.1.2
waitress==1.4.4
waitress==2.0.0
pyxform==1.4.0