From 8fe49b6b356559f24106630d39f1601364ccd2a9 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Wed, 7 Jun 2023 09:16:11 -0500 Subject: [PATCH] [stable-2.15] URI Module find json sub type (#80745) (#80891) * uri: fixed search for json types to include strings in the format xxx/yyy+json (cherry picked from commit 0c7361d9acf7c8966a09f67de2a8679ef86fd856) Co-authored-by: Brent Barbachem --- changelogs/fragments/update-maybe-json-uri.yml | 2 ++ lib/ansible/modules/uri.py | 10 +++++++++- test/integration/targets/uri/tasks/main.yml | 12 ++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/update-maybe-json-uri.yml diff --git a/changelogs/fragments/update-maybe-json-uri.yml b/changelogs/fragments/update-maybe-json-uri.yml new file mode 100644 index 00000000000..7cf693d2ce2 --- /dev/null +++ b/changelogs/fragments/update-maybe-json-uri.yml @@ -0,0 +1,2 @@ +bugfixes: +- uri - fix search for JSON type to include complex strings containing '+' diff --git a/lib/ansible/modules/uri.py b/lib/ansible/modules/uri.py index 03ba66fa87e..77d81dd2f50 100644 --- a/lib/ansible/modules/uri.py +++ b/lib/ansible/modules/uri.py @@ -707,7 +707,15 @@ def main(): sub_type = 'octet-stream' content_encoding = 'utf-8' - maybe_json = content_type and sub_type.lower() in JSON_CANDIDATES + if sub_type and '+' in sub_type: + # https://www.rfc-editor.org/rfc/rfc6839#section-3.1 + sub_type_suffix = sub_type.partition('+')[2] + maybe_json = content_type and sub_type_suffix.lower() in JSON_CANDIDATES + elif sub_type: + maybe_json = content_type and sub_type.lower() in JSON_CANDIDATES + else: + maybe_json = False + maybe_output = maybe_json or return_content or info['status'] not in status_code if maybe_output: diff --git a/test/integration/targets/uri/tasks/main.yml b/test/integration/targets/uri/tasks/main.yml index f55431e5dd5..42b04735d0b 100644 --- a/test/integration/targets/uri/tasks/main.yml +++ b/test/integration/targets/uri/tasks/main.yml @@ -696,6 +696,18 @@ that: - result.json.json[0] == 'JSON Test Pattern pass1' +- name: Test find JSON as subtype + uri: + url: "https://{{ httpbin_host }}/response-headers?content-type=application/ld%2Bjson" + method: POST + return_content: true + register: result + +- name: Validate JSON as subtype + assert: + that: + - result.json is defined + - name: Make request that includes password in JSON keys uri: url: "https://{{ httpbin_host}}/get?key-password=value-password"