Skip to content

Commit

Permalink
Edit workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
peteroupc committed Jan 16, 2025
1 parent 5ffc2ef commit 5ae5871
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 3 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
69 changes: 69 additions & 0 deletions CBORTest/QueryStringHelperCBOR.cs
Original file line number Diff line number Diff line change
@@ -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<object> dict) {
var cbor = CBORObject.NewArray();
for (int i = 0; i < dict.Count; ++i) {
object di = dict[i];
var value = di as IDictionary<string, object>;
// A list contains only integer indices,
// with no gaps.
if (QueryStringHelper.IsList(value)) {
IList<object> 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<string, object>
dict) {
var cbor = CBORObject.NewMap();
foreach (string key in new List<string>(dict.Keys)) {
object di = dict[key];
var value = di as IDictionary<string, object>;
// A list contains only integer indices,
// with no gaps.
if (QueryStringHelper.IsList(value)) {
IList<object> 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));
}
}
}

0 comments on commit 5ae5871

Please sign in to comment.