From 5ae58714af01abc54734c5589a227973995b636a Mon Sep 17 00:00:00 2001 From: Peter Occil Date: Thu, 16 Jan 2025 03:37:37 -0500 Subject: [PATCH] Edit workflow --- .github/workflows/codeql-analysis.yml | 6 +-- CBORTest/QueryStringHelperCBOR.cs | 69 +++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 CBORTest/QueryStringHelperCBOR.cs diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index cfe0c474..ea08c9ab 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -43,7 +43,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@v3 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -56,10 +56,10 @@ jobs: with: dotnet-version: '9.0' - name: Autobuild - uses: github/codeql-action/autobuild@v2 + uses: github/codeql-action/autobuild@v3 #- run: | # dotnet clean; dotnet build CBORTest -c Release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@v3 diff --git a/CBORTest/QueryStringHelperCBOR.cs b/CBORTest/QueryStringHelperCBOR.cs new file mode 100644 index 00000000..b94ecd85 --- /dev/null +++ b/CBORTest/QueryStringHelperCBOR.cs @@ -0,0 +1,69 @@ +// Written by Peter O. +// Any copyright to this work is released to the Public Domain. +// In case this is not possible, this work is also +// licensed under the Unlicense: https://unlicense.org/ + +using System; +using System.Collections.Generic; +using System.Text; +using PeterO.Cbor; + +namespace PeterO { + public sealed class QueryStringHelperCBOR { + private QueryStringHelperCBOR() { + } + private static CBORObject ConvertListsToCBOR(IList dict) { + var cbor = CBORObject.NewArray(); + for (int i = 0; i < dict.Count; ++i) { + object di = dict[i]; + var value = di as IDictionary; + // A list contains only integer indices, + // with no gaps. + if (QueryStringHelper.IsList(value)) { + IList newList = QueryStringHelper.ConvertToList(value); + _ = cbor.Add(ConvertListsToCBOR(newList)); + } else if (value != null) { + // Convert the list's descendents + // if they are lists + _ = cbor.Add(ConvertListsToCBOR(value)); + } else { + _ = cbor.Add(dict[i]); + } + } + return cbor; + } + + private static CBORObject ConvertListsToCBOR(IDictionary + dict) { + var cbor = CBORObject.NewMap(); + foreach (string key in new List(dict.Keys)) { + object di = dict[key]; + var value = di as IDictionary; + // A list contains only integer indices, + // with no gaps. + if (QueryStringHelper.IsList(value)) { + IList newList = QueryStringHelper.ConvertToList(value); + _ = cbor.Add(key, ConvertListsToCBOR(newList)); + } else if (value != null) { + // Convert the dictionary's descendents + // if they are lists + _ = cbor.Add(key, ConvertListsToCBOR(value)); + } else { + _ = cbor.Add(key, dict[key]); + } + } + return cbor; + } + + public static CBORObject QueryStringToCBOR(string query) { + return QueryStringToCBOR(query, "&"); + } + public static CBORObject QueryStringToCBOR(string query, + string delimiter) { + // Convert array-like dictionaries to ILists + return +ConvertListsToCBOR(QueryStringHelper.QueryStringToDictInternal(query, + delimiter)); + } + } +}