diff --git a/.github/actions/render/defaults/action.yml b/.github/actions/render/defaults/action.yml index 5dc1b2988..4942e00d4 100644 --- a/.github/actions/render/defaults/action.yml +++ b/.github/actions/render/defaults/action.yml @@ -14,6 +14,10 @@ inputs: description: "Set the macro to disable the default traits" required: false default: "true" +outputs: + file_path: + description: "Relative path which the 'defaults.h' was written to" + value: ${{ steps.script.outputs.result }} runs: using: composite steps: @@ -23,12 +27,14 @@ runs: - run: npm install mustache shell: bash - uses: actions/github-script@v6 + id: script env: TRAITS_NAME: ${{ inputs.traits_name }} LIBRARY_NAME: ${{ inputs.library_name }} LIBRARY_URL: ${{ inputs.library_url }} DISABLE_DEFAULT_TRAITS: ${{ inputs.disable_default_traits }} with: + result-encoding: string script: | const mustache = require('mustache') const path = require('path') @@ -54,4 +60,8 @@ runs: const outputDir = path.join('include', 'jwt-cpp', 'traits', replaceAll(TRAITS_NAME, '_', '-')) fs.mkdirSync(outputDir, { recursive: true }) - fs.writeFileSync(path.join(outputDir, 'defaults.h'), content) + + const filePath = path.join(outputDir, 'defaults.h') + fs.writeFileSync(filePath, content) + + return filePath diff --git a/.github/actions/render/tests/action.yml b/.github/actions/render/tests/action.yml index 7f798627c..fe1f58649 100644 --- a/.github/actions/render/tests/action.yml +++ b/.github/actions/render/tests/action.yml @@ -28,10 +28,15 @@ runs: const { TRAITS_NAME, SUITE_NAME } = process.env console.log(`Rendering ${TRAITS_NAME}!`) + // https://dmitripavlutin.com/replace-all-string-occurrences-javascript/ + function replaceAll(string, search, replace) { + return string.split(search).join(replace); + } + const template = fs.readFileSync(path.join('tests', 'traits', 'TraitsTest.cpp.mustache'), 'utf8') const content = mustache.render(template, { traits_name: TRAITS_NAME, - traits_dir: TRAITS_NAME.replace('_', '-'), + traits_dir: replaceAll(TRAITS_NAME, '_', '-'), test_suite_name: SUITE_NAME, }) const outputDir = path.join('tests', 'traits') diff --git a/.github/workflows/jwt.yml b/.github/workflows/jwt.yml index 04ab7070d..46e35ccc6 100644 --- a/.github/workflows/jwt.yml +++ b/.github/workflows/jwt.yml @@ -15,6 +15,7 @@ jobs: - uses: ./.github/actions/install/gtest - uses: ./.github/actions/install/danielaparker-jsoncons - uses: ./.github/actions/install/boost-json + - uses: ./.github/actions/install/open-source-parsers-jsoncpp - name: configure run: | diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index a166c63ad..c2b3bfd3e 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -80,13 +80,14 @@ jobs: steps: - uses: actions/checkout@v3 - uses: ./.github/actions/render/defaults + id: render with: traits_name: ${{ matrix.traits.name }} library_name: ${{ matrix.traits.library }} library_url: ${{ matrix.traits.url }} disable_default_traits: ${{ matrix.traits.disable_pico }} - - run: clang-format -i include/jwt-cpp/traits/**/*.h - - run: git add include/jwt-cpp/traits/* + - run: clang-format -i ${{ steps.render.outputs.file_path }} + - run: git add ${{ steps.render.outputs.file_path }} - uses: ./.github/actions/process-linting-results with: linter_name: render-defaults diff --git a/include/jwt-cpp/traits/open-source-parsers-jsoncpp/traits.h b/include/jwt-cpp/traits/open-source-parsers-jsoncpp/traits.h index 1d4c0c7d6..16f76f1b1 100644 --- a/include/jwt-cpp/traits/open-source-parsers-jsoncpp/traits.h +++ b/include/jwt-cpp/traits/open-source-parsers-jsoncpp/traits.h @@ -66,10 +66,11 @@ namespace jwt { return type::array; else if (val.isString()) return type::string; - else if (val.isNumeric()) - return type::number; + // Order is important https://github.com/Thalhammer/jwt-cpp/pull/320#issuecomment-1865322511 else if (val.isInt()) return type::integer; + else if (val.isNumeric()) + return type::number; else if (val.isBool()) return type::boolean; else if (val.isObject()) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0b88b5e74..2c39d9f28 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -67,6 +67,9 @@ else() if(TARGET boost_json) target_link_libraries(jwt-cpp-test PRIVATE boost_json) endif() + if(TARGET jsoncpp_static) + target_link_libraries(jwt-cpp-test PRIVATE jsoncpp_static) + endif() endif() target_link_libraries(jwt-cpp-test PRIVATE jwt-cpp nlohmann_json::nlohmann_json $<$>:${CMAKE_DL_LIBS}>) diff --git a/tests/traits/OspJsoncppTest.cpp b/tests/traits/OspJsoncppTest.cpp index 1b65fa5ab..f0bd3d533 100644 --- a/tests/traits/OspJsoncppTest.cpp +++ b/tests/traits/OspJsoncppTest.cpp @@ -1,4 +1,4 @@ -#include "jwt-cpp/traits/open-source_parsers_jsoncpp/traits.h" +#include "jwt-cpp/traits/open-source-parsers-jsoncpp/traits.h" #include