Merge branch 'main' into dane/newunescape

This commit is contained in:
Dane Walton 2022-11-09 22:42:29 -05:00
Родитель 68f231a42e c770dd2f04
Коммит bace5a0ce9
27 изменённых файлов: 140 добавлений и 252 удалений

2
.github/workflows/event.yml поставляемый
Просмотреть файл

@ -15,7 +15,7 @@ jobs:
event-handler:
permissions:
statuses: write # to set status (azure/azure-sdk-actions)
pull-requests: read # to read pull requests (azure/azure-sdk-actions)
pull-requests: write # to read pull requests and write comments (azure/azure-sdk-actions)
checks: read # to read check status (azure/azure-sdk-actions)
name: Handle ${{ github.event_name }} ${{ github.event.action }} event
runs-on: ubuntu-latest

1
.vscode/cspell.json поставляемый
Просмотреть файл

@ -48,6 +48,7 @@
"mkdir",
"moxygen",
"mqtt",
"MQTTCLIENT",
"mspremier",
"MSRC",
"MSVC",

Просмотреть файл

@ -4,13 +4,15 @@
### Features Added
[[#2329](https://github.com/Azure/azure-sdk-for-c/pull/2329)] Add Base64 URL decoder.
- [[#2329](https://github.com/Azure/azure-sdk-for-c/pull/2329)] Add Base64 URL decoder.
### Breaking Changes
- Modified the `az_json_string_unescape()` function signature to accept `az_span` as the destination.
### Bugs Fixed
[[#2372](https://github.com/Azure/azure-sdk-for-c/pull/2372)] Incorrect minimum buffer size calculation when logging an HTTP request.
- [[#2372](https://github.com/Azure/azure-sdk-for-c/pull/2372)] Incorrect minimum buffer size calculation when logging an HTTP request.
### Other Changes

Просмотреть файл

@ -4,41 +4,37 @@
# Defines utilities for Azure SDK to integrate with VCPKG automatically
macro(az_vcpkg_integrate)
message("Vcpkg integrate step.")
# AUTO CMAKE_TOOLCHAIN_FILE:
# User can call `cmake -DCMAKE_TOOLCHAIN_FILE="path_to_the_toolchain"` as the most specific scenario.
# An env var VCPKG_ROOT or VCPKG_INSTALLATION_ROOT can be set to let Azure SDK to set the VCPKG toolchain automatically.
# As the last alternative (default case), Azure SDK will automatically clone VCPKG folder and set toolchain from there.
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
if(DEFINED ENV{VCPKG_ROOT})
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "")
elseif(DEFINED ENV{VCPKG_INSTALLATION_ROOT})
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_INSTALLATION_ROOT}/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "")
else()
# Set AZURE_SDK_DISABLE_AUTO_VCPKG env var to avoid Azure SDK from cloning and setting VCPKG automatically
# This option delegate package's dependencies installation to user.
if(NOT DEFINED ENV{AZURE_SDK_DISABLE_AUTO_VCPKG})
# GET VCPKG FROM SOURCE
# User can set env var AZURE_SDK_VCPKG_COMMIT to pick the VCPKG commit to fetch
set(VCPKG_COMMIT_STRING f0aa678b7471497f1adedcc99f40e1599ad22f69) # default SDK tested commit
if(DEFINED ENV{AZURE_SDK_VCPKG_COMMIT})
set(VCPKG_COMMIT_STRING "$ENV{AZURE_SDK_VCPKG_COMMIT}") # default SDK tested commit
endif()
include(FetchContent)
FetchContent_Declare(
vcpkg
GIT_REPOSITORY https://github.com/microsoft/vcpkg.git
GIT_TAG ${VCPKG_COMMIT_STRING}
)
FetchContent_GetProperties(vcpkg)
# make sure to pull vcpkg only once.
if(NOT vcpkg_POPULATED)
FetchContent_Populate(vcpkg)
endif()
# use the vcpkg source path
set(CMAKE_TOOLCHAIN_FILE "${vcpkg_SOURCE_DIR}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
message("CMAKE_TOOLCHAIN_FILE is not defined. Define it for the user.")
# Set AZURE_SDK_DISABLE_AUTO_VCPKG env var to avoid Azure SDK from cloning and setting VCPKG automatically
# This option delegate package's dependencies installation to user.
if(NOT DEFINED ENV{AZURE_SDK_DISABLE_AUTO_VCPKG})
message("AZURE_SDK_DISABLE_AUTO_VCPKG is not defined. Fetch a local copy of vcpkg.")
# GET VCPKG FROM SOURCE
# User can set env var AZURE_SDK_VCPKG_COMMIT to pick the VCPKG commit to fetch
set(VCPKG_COMMIT_STRING 94ce0dab56f4d8ba6bd631ba59ed682b02d45c46) # default SDK tested commit
if(DEFINED ENV{AZURE_SDK_VCPKG_COMMIT})
message("AZURE_SDK_VCPKG_COMMIT is defined. Using that instead of the default.")
set(VCPKG_COMMIT_STRING "$ENV{AZURE_SDK_VCPKG_COMMIT}") # default SDK tested commit
endif()
message("Vcpkg commit string used: ${VCPKG_COMMIT_STRING}")
include(FetchContent)
FetchContent_Declare(
vcpkg
GIT_REPOSITORY https://github.com/microsoft/vcpkg.git
GIT_TAG ${VCPKG_COMMIT_STRING}
)
FetchContent_GetProperties(vcpkg)
# make sure to pull vcpkg only once.
if(NOT vcpkg_POPULATED)
FetchContent_Populate(vcpkg)
endif()
# use the vcpkg source path
set(CMAKE_TOOLCHAIN_FILE "${vcpkg_SOURCE_DIR}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
endif()
endif()

Просмотреть файл

@ -2,6 +2,7 @@
"azureAuthorityHost": "https://login.microsoftonline.com/",
"cognitiveServicesEndpointSuffix": ".cognitiveservices.azure.com",
"communicationServicesEndpointSuffix": ".communication.azure.com",
"cosmosEndpointSuffix": "cosmos.azure.com",
"keyVaultDomainSuffix": ".vault.azure.net",
"keyVaultEndpointSuffix": ".vault.azure.net",
"storageEndpointSuffix": "core.windows.net"

Просмотреть файл

@ -18,8 +18,8 @@ steps:
- task: NodeTool@0
condition: and(succeededOrFailed(), ne(variables['Skip.SpellCheck'],'true'))
inputs:
versionSpec: 16.x
displayName: Use Node.js 16.x
versionSpec: 18.x
displayName: Use Node.js 18.x
- task: PowerShell@2
displayName: Check spelling (cspell)

Просмотреть файл

@ -31,6 +31,12 @@ Output location for unified reference yml file
.PARAMETER ReadmeFolderRoot
The readme folder root path, use default value here for backward compability. E.g. docs-ref-services in Java, JS, Python, api/overview/azure
.PARAMETER PackageSourceOverride
Optional parameter to supply a different package source (useful for daily dev
docs generation from pacakges which are not published to the default feed). This
variable is meant to be used in the domain-specific business logic in
&$GetDocsMsTocDataFn
#>
param(
@ -41,7 +47,10 @@ param(
[string] $OutputLocation,
[Parameter(Mandatory = $false)]
[string] $ReadmeFolderRoot = 'docs-ref-services'
[string] $ReadmeFolderRoot = 'docs-ref-services',
[Parameter(Mandatory = $false)]
[string] $PackageSourceOverride
)
. $PSScriptRoot/common.ps1
. $PSScriptRoot/Helpers/PSModule-Helpers.ps1
@ -53,7 +62,8 @@ Set-StrictMode -Version 3
function GetPackageNode($package) {
$packageInfo = &$GetDocsMsTocDataFn `
-packageMetadata $package `
-docRepoLocation $DocRepoLocation
-docRepoLocation $DocRepoLocation `
-PackageSourceOverride $PackageSourceOverride
return [PSCustomObject]@{
name = $packageInfo.PackageTocHeader

Просмотреть файл

@ -86,7 +86,8 @@ function MatchesAnnotations([hashtable]$chart, [hashtable]$filters) {
function VerifyAddonsVersion([hashtable]$chart, [string]$chartFile) {
foreach ($dependency in $chart.dependencies) {
if ($dependency.name -eq "stress-test-addons" -and
$dependency.version -lt "0.2.0") {
$dependency.version -like '0.1.*' -or
$dependency.version -like '^0.1.*') {
throw "The stress-test-addons version in use for '$chartFile' is $($dependency.version), please use versions >= 0.2.0"
}
}

Просмотреть файл

@ -5,6 +5,19 @@ $FailedCommands = New-Object Collections.Generic.List[hashtable]
. (Join-Path $PSScriptRoot "../Helpers" PSModule-Helpers.ps1)
$limitRangeSpec = @"
apiVersion: v1
kind: LimitRange
metadata:
name: default-resource-request
spec:
limits:
- defaultRequest:
cpu: 100m
memory: 100Mi
type: Container
"@
# Powershell does not (at time of writing) treat exit codes from external binaries
# as cause for stopping execution, so do this via a wrapper function.
# See https://github.com/PowerShell/PowerShell-RFC/pull/277
@ -191,6 +204,9 @@ function DeployStressPackage(
Write-Host "Creating namespace $($pkg.Namespace) if it does not exist..."
kubectl create namespace $pkg.Namespace --dry-run=client -o yaml | kubectl apply -f -
if ($LASTEXITCODE) {exit $LASTEXITCODE}
Write-Host "Adding default resource requests to namespace/$($pkg.Namespace)"
$limitRangeSpec | kubectl apply -n $pkg.Namespace -f -
if ($LASTEXITCODE) {exit $LASTEXITCODE}
$dockerBuildConfigs = @()

Просмотреть файл

@ -167,10 +167,12 @@ $originalLocation = Get-Location
try {
Set-Location $PackageInstallCache
npm install npx | Out-Null
npm install cspell | Out-Null
npm install | Out-Null
# Use the mutated configuration file when calling cspell
$command = "npx --no-install cspell $JobType --config $CSpellConfigPath --no-must-find-files --root $SpellCheckRoot --relative"
$command = "npx cspell $JobType --config $CSpellConfigPath --no-must-find-files --root $SpellCheckRoot --relative"
Write-Host $command
$cspellOutput = npx `
--no-install `

Просмотреть файл

@ -1 +1 @@
1.0.0-dev.20221031.1
1.0.0-dev.20221102.1

Просмотреть файл

@ -1 +1 @@
tags/2020.06
tags/2022.10.19

Просмотреть файл

@ -796,28 +796,24 @@ AZ_NODISCARD az_result az_json_reader_skip_children(az_json_reader* ref_json_rea
* @brief Unescapes the JSON string within the provided #az_span.
*
* @param[in] json_string The #az_span that contains the string to be unescaped.
* @param destination Pointer to the buffer that will contain the output.
* @param[in] destination_max_size The maximum available space within the buffer referred to by
* \p destination.
* @param[out] out_string_length __[nullable]__ Contains the number of bytes written to the
* \p destination which denote the length of the unescaped string. If `NULL` is passed, the
* \p parameter is ignored.
* @param destination The destination buffer used to write the unescaped output into.
*
* @return An #az_result value indicating the result of the operation.
* @retval #AZ_OK The string is returned.
* @retval #AZ_ERROR_NOT_ENOUGH_SPACE \p destination does not have enough size.
* @return An #az_span that is a slice of the \p destination #az_span containing the unescaped JSON
* string, which denotes the length of the unescaped string.
*
* @remarks The buffer referred to by \p destination must have a size that is at least 1 byte bigger
* than the \p json_string #az_span for the \p destination string to be zero-terminated.
* Content is copied from the source buffer, while unescaping and then `\0` is added at the end.
* @remarks For user-defined or unknown input, the buffer referred to by \p destination must be at
* least as large as the \p json_string #az_span. Content is copied from the source buffer, while
* unescaping.
*
* @remarks This API can also be used to perform in place unescaping.
* @remarks This function assumes that the \p json_string input is well-formed JSON.
*
* @remarks This function assumes that the \p destination has a large enough size to hold the
* unescaped \p json_string.
*
* @remarks This API can also be used to perform in place unescaping. However, doing so, is
* destructive and the input JSON may no longer be valid or parsable.
*/
AZ_NODISCARD az_result az_json_string_unescape(
az_span json_string,
char* destination,
int32_t destination_max_size,
int32_t* out_string_length);
AZ_NODISCARD az_span az_json_string_unescape(az_span json_string, az_span destination);
#include <azure/core/_az_cfg_suffix.h>

Просмотреть файл

@ -12,7 +12,7 @@
// warning C4201: nonstandard extension used: nameless struct/union
#pragma warning(disable : 4201)
#endif
#include <paho-mqtt/MQTTClient.h>
#include <MQTTClient.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif

Просмотреть файл

@ -12,7 +12,7 @@
// warning C4201: nonstandard extension used: nameless struct/union
#pragma warning(disable : 4201)
#endif
#include <paho-mqtt/MQTTClient.h>
#include <MQTTClient.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif

Просмотреть файл

@ -12,7 +12,7 @@
// warning C4201: nonstandard extension used: nameless struct/union
#pragma warning(disable : 4201)
#endif
#include <paho-mqtt/MQTTClient.h>
#include <MQTTClient.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif

Просмотреть файл

@ -12,7 +12,7 @@
// warning C4201: nonstandard extension used: nameless struct/union
#pragma warning(disable : 4201)
#endif
#include <paho-mqtt/MQTTClient.h>
#include <MQTTClient.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif

Просмотреть файл

@ -12,7 +12,7 @@
// warning C4201: nonstandard extension used: nameless struct/union
#pragma warning(disable : 4201)
#endif
#include <paho-mqtt/MQTTClient.h>
#include <MQTTClient.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif

Просмотреть файл

@ -24,7 +24,7 @@
// warning C4201: nonstandard extension used: nameless struct/union
#pragma warning(disable : 4201)
#endif
#include <paho-mqtt/MQTTClient.h>
#include <MQTTClient.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif

Просмотреть файл

@ -30,7 +30,7 @@
// warning C4201: nonstandard extension used: nameless struct/union
#pragma warning(disable : 4201)
#endif
#include <paho-mqtt/MQTTClient.h>
#include <MQTTClient.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif

Просмотреть файл

@ -23,7 +23,7 @@
// warning C4201: nonstandard extension used: nameless struct/union
#pragma warning(disable : 4201)
#endif
#include <paho-mqtt/MQTTClient.h>
#include <MQTTClient.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif

Просмотреть файл

@ -12,7 +12,7 @@
// warning C4201: nonstandard extension used: nameless struct/union
#pragma warning(disable : 4201)
#endif
#include <paho-mqtt/MQTTClient.h>
#include <MQTTClient.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif

Просмотреть файл

@ -12,7 +12,7 @@
// warning C4201: nonstandard extension used: nameless struct/union
#pragma warning(disable : 4201)
#endif
#include <paho-mqtt/MQTTClient.h>
#include <MQTTClient.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif

Просмотреть файл

@ -13,7 +13,7 @@
// warning C4201: nonstandard extension used: nameless struct/union
#pragma warning(disable : 4201)
#endif
#include <paho-mqtt/MQTTClient.h>
#include <MQTTClient.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif

Просмотреть файл

@ -325,20 +325,19 @@ AZ_NODISCARD static az_result _az_json_token_get_string_helper(
return AZ_OK;
}
AZ_NODISCARD az_result az_json_string_unescape(
az_span json_string,
char* destination,
int32_t destination_max_size,
int32_t* out_string_length)
AZ_NODISCARD az_span az_json_string_unescape(az_span json_string, az_span destination)
{
_az_PRECONDITION_VALID_SPAN(json_string, 1, false);
_az_PRECONDITION_NOT_NULL(destination);
// The destination needs to be larger than the input, for null terminator.
_az_PRECONDITION(destination_max_size > az_span_size(json_string));
int32_t span_size = az_span_size(json_string);
// The destination needs to be at least as large as the input, in the worst case.
_az_PRECONDITION_VALID_SPAN(destination, span_size, false);
int32_t position = 0;
int32_t span_size = az_span_size(json_string);
uint8_t* span_ptr = az_span_ptr(json_string);
uint8_t* destination_ptr = az_span_ptr(destination);
int32_t destination_size = az_span_size(destination);
for (int32_t i = 0; i < span_size; i++)
{
uint8_t current_char = span_ptr[i];
@ -353,32 +352,29 @@ AZ_NODISCARD az_result az_json_string_unescape(
}
else
{
return AZ_ERROR_UNEXPECTED_CHAR;
// We assume that the input json is well-formed, but stop processing, in-case it isn't.
return az_span_slice(destination, 0, position);
}
}
else if (current_char == '\\')
{
// At this point, we are at the last character, i == span_size - 1
return AZ_ERROR_UNEXPECTED_END;
// We assume that the input json is well-formed, but stop processing, in-case it isn't.
return az_span_slice(destination, 0, position);
}
if (position > destination_max_size)
if (position > destination_size)
{
return AZ_ERROR_NOT_ENOUGH_SPACE;
// We assume that the destination buffer is large enough, but stop processing, in-case it
// isn't.
return az_span_slice(destination, 0, position);
}
destination[position] = (char)current_char;
destination_ptr[position] = current_char;
position++;
}
destination[position] = 0;
if (out_string_length != NULL)
{
*out_string_length = position;
}
return AZ_OK;
return az_span_slice(destination, 0, position);
}
AZ_NODISCARD az_result az_json_token_get_string(

Просмотреть файл

@ -3004,32 +3004,12 @@ static void test_az_json_string_unescape(void** state)
char destination[59] = { 0 };
az_span destination_span = AZ_SPAN_FROM_BUFFER(destination);
int final_size;
az_result result = az_json_string_unescape(json, destination, 59, &final_size);
destination_span = az_json_string_unescape(json, destination_span);
destination_span = az_span_slice(destination_span, 0, final_size);
assert_int_equal(AZ_OK, result);
assert_true(az_span_is_content_equal(expected, destination_span));
}
// unexpected end
{
uint8_t buffer[3];
az_span test_span = AZ_SPAN_FROM_BUFFER(buffer);
test_span._internal.ptr[0] = 'a';
test_span._internal.ptr[1] = 'b';
test_span._internal.ptr[2] = '\\';
char destination[59] = { 0 };
int final_size;
az_result result = az_json_string_unescape(test_span, destination, 59, &final_size);
assert_int_equal(AZ_ERROR_UNEXPECTED_END, result);
}
// null terminator
// nothing is written past the end (including null terminator)
{
uint8_t buffer[3];
az_span test_span = AZ_SPAN_FROM_BUFFER(buffer);
@ -3040,17 +3020,12 @@ static void test_az_json_string_unescape(void** state)
az_span expected = AZ_SPAN_FROM_STR("ab");
char destination[59] = { 0 };
destination[2] = 'd'; // verify that 'd' is overwritten with 0
destination[2] = 'd'; // verify that 'd' is not overwritten with 0
az_span destination_span = AZ_SPAN_FROM_BUFFER(destination);
int final_size;
az_result result
= az_json_string_unescape(az_span_slice(test_span, 0, 2), destination, 59, &final_size);
destination_span = az_json_string_unescape(az_span_slice(test_span, 0, 2), destination_span);
destination_span = az_span_slice(destination_span, 0, final_size);
assert_int_equal(0, (int)destination[2]);
assert_int_equal(AZ_OK, result);
assert_int_equal((int)'d', (int)destination[2]);
assert_true(az_span_is_content_equal(expected, destination_span));
}
@ -3062,12 +3037,8 @@ static void test_az_json_string_unescape(void** state)
char destination[59] = { 0 };
az_span destination_span = AZ_SPAN_FROM_BUFFER(destination);
int final_size;
az_result result = az_json_string_unescape(original, destination, 59, &final_size);
destination_span = az_json_string_unescape(original, destination_span);
destination_span = az_span_slice(destination_span, 0, final_size);
assert_int_equal(AZ_OK, result);
assert_true(az_span_is_content_equal(expected, destination_span));
}
@ -3080,39 +3051,11 @@ static void test_az_json_string_unescape(void** state)
char destination[59] = { 0 };
az_span destination_span = AZ_SPAN_FROM_BUFFER(destination);
int final_size;
az_result result = az_json_string_unescape(original, destination, 59, &final_size);
destination_span = az_json_string_unescape(original, destination_span);
destination_span = az_span_slice(destination_span, 0, final_size);
assert_int_equal(AZ_OK, result);
assert_true(az_span_is_content_equal(expected, destination_span));
}
// fake escapes
{
az_span original = AZ_SPAN_FROM_STR("\\9");
char destination[59] = { 0 };
int final_size;
az_result result = az_json_string_unescape(original, destination, 59, &final_size);
assert_int_equal(AZ_ERROR_UNEXPECTED_CHAR, result);
}
// malformed escapes
{
az_span original = AZ_SPAN_FROM_STR("abcd\\");
char destination[59] = { 0 };
int final_size;
az_result result = az_json_string_unescape(original, destination, 59, &final_size);
assert_int_equal(AZ_ERROR_UNEXPECTED_END, result);
}
// single char
{
az_span original = AZ_SPAN_FROM_STR("a");
@ -3121,12 +3064,8 @@ static void test_az_json_string_unescape(void** state)
char destination[59] = { 0 };
az_span destination_span = AZ_SPAN_FROM_BUFFER(destination);
int final_size;
az_result result = az_json_string_unescape(original, destination, 59, &final_size);
destination_span = az_json_string_unescape(original, destination_span);
destination_span = az_span_slice(destination_span, 0, final_size);
assert_int_equal(AZ_OK, result);
assert_true(az_span_is_content_equal(expected, destination_span));
}
@ -3137,12 +3076,8 @@ static void test_az_json_string_unescape(void** state)
char destination[59] = { 0 };
az_span destination_span = AZ_SPAN_FROM_BUFFER(destination);
int final_size;
az_result result = az_json_string_unescape(original, destination, 59, &final_size);
destination_span = az_json_string_unescape(original, destination_span);
destination_span = az_span_slice(destination_span, 0, final_size);
assert_int_equal(AZ_OK, result);
assert_true(az_span_is_content_equal(expected, destination_span));
}
@ -3153,12 +3088,8 @@ static void test_az_json_string_unescape(void** state)
char destination[59] = { 0 };
az_span destination_span = AZ_SPAN_FROM_BUFFER(destination);
int final_size;
az_result result = az_json_string_unescape(original, destination, 59, &final_size);
destination_span = az_json_string_unescape(original, destination_span);
destination_span = az_span_slice(destination_span, 0, final_size);
assert_int_equal(AZ_OK, result);
assert_true(az_span_is_content_equal(expected, destination_span));
}
@ -3170,12 +3101,8 @@ static void test_az_json_string_unescape(void** state)
char destination[59] = { 0 };
az_span destination_span = AZ_SPAN_FROM_BUFFER(destination);
int final_size;
az_result result = az_json_string_unescape(original, destination, 59, &final_size);
destination_span = az_json_string_unescape(original, destination_span);
destination_span = az_span_slice(destination_span, 0, final_size);
assert_int_equal(AZ_OK, result);
assert_true(az_span_is_content_equal(expected, destination_span));
}
@ -3187,12 +3114,8 @@ static void test_az_json_string_unescape(void** state)
char destination[59] = { 0 };
az_span destination_span = AZ_SPAN_FROM_BUFFER(destination);
int final_size;
az_result result = az_json_string_unescape(original, destination, 59, &final_size);
destination_span = az_json_string_unescape(original, destination_span);
destination_span = az_span_slice(destination_span, 0, final_size);
assert_int_equal(AZ_OK, result);
assert_true(az_span_is_content_equal(expected, destination_span));
}
@ -3204,12 +3127,8 @@ static void test_az_json_string_unescape(void** state)
char destination[59] = { 0 };
az_span destination_span = AZ_SPAN_FROM_BUFFER(destination);
int final_size;
az_result result = az_json_string_unescape(original, destination, 59, &final_size);
destination_span = az_json_string_unescape(original, destination_span);
destination_span = az_span_slice(destination_span, 0, final_size);
assert_int_equal(AZ_OK, result);
assert_true(az_span_is_content_equal(expected, destination_span));
}
@ -3219,9 +3138,9 @@ static void test_az_json_string_unescape(void** state)
az_span expected = AZ_SPAN_FROM_STR("My name is \\\"Ahson\"!");
char destination[59] = { 0 };
az_result result = az_json_string_unescape(original, destination, 59, NULL);
az_span destination_span = AZ_SPAN_FROM_BUFFER(destination);
destination_span = az_json_string_unescape(original, destination_span);
assert_int_equal(AZ_OK, result);
assert_string_equal((char*)az_span_ptr(expected), destination);
}
@ -3231,9 +3150,9 @@ static void test_az_json_string_unescape(void** state)
az_span expected = AZ_SPAN_FROM_STR("//\"");
char destination[59] = { 0 };
az_result result = az_json_string_unescape(original, destination, 59, NULL);
az_span destination_span = AZ_SPAN_FROM_BUFFER(destination);
destination_span = az_json_string_unescape(original, destination_span);
assert_int_equal(AZ_OK, result);
assert_string_equal((char*)az_span_ptr(expected), destination);
}
}
@ -3250,33 +3169,26 @@ static void test_az_json_string_unescape_same_buffer(void** state)
az_span expected
= AZ_SPAN_FROM_STR(" { \"name\": \"some value string\" , \"code\" : 123456 } ");
int final_size;
az_result result = az_json_string_unescape(json, (char*)az_span_ptr(json), 59, &final_size);
json = az_json_string_unescape(json, json);
json = az_span_slice(json, 0, final_size);
assert_int_equal(AZ_OK, result);
assert_true(az_span_is_content_equal(expected, json));
_az_span_free(&json);
}
// null terminator
// nothing is written past the end (including null terminator)
{
uint8_t buffer[3];
az_span test_span = AZ_SPAN_FROM_BUFFER(buffer);
test_span._internal.ptr[0] = 'a';
test_span._internal.ptr[1] = 'b';
test_span._internal.ptr[2] = 'c'; // verify that 'c' is overwritten with 0
test_span._internal.ptr[2] = 'c'; // verify that 'c' is not overwritten with 0
az_span expected = AZ_SPAN_FROM_STR("ab");
int final_size;
az_result result = az_json_string_unescape(
az_span_slice(test_span, 0, 2), (char*)az_span_ptr(test_span), 59, &final_size);
test_span = az_json_string_unescape(az_span_slice(test_span, 0, 2), test_span);
assert_int_equal(0, test_span._internal.ptr[2]);
assert_int_equal(AZ_OK, result);
assert_true(az_span_is_content_equal(expected, az_span_slice(test_span, 0, final_size)));
assert_int_equal((int)'c', buffer[2]);
assert_true(az_span_is_content_equal(expected, az_span_slice(test_span, 0, 2)));
}
// only escapes
@ -3284,13 +3196,8 @@ static void test_az_json_string_unescape_same_buffer(void** state)
az_span original = az_span_create_from_str(strdup("\\b\\f\\n\\r\\t\\\\"));
az_span expected = AZ_SPAN_FROM_STR("\b\f\n\r\t\\");
int final_size;
az_result result
= az_json_string_unescape(original, (char*)az_span_ptr(original), 59, &final_size);
original = az_json_string_unescape(original, original);
original = az_span_slice(original, 0, final_size);
assert_int_equal(AZ_OK, result);
assert_true(az_span_is_content_equal(expected, original));
_az_span_free(&original);
}
@ -3300,13 +3207,8 @@ static void test_az_json_string_unescape_same_buffer(void** state)
az_span original = az_span_create_from_str(strdup("\\/\\/\\\""));
az_span expected = AZ_SPAN_FROM_STR("//\"");
int final_size;
az_result result
= az_json_string_unescape(original, (char*)az_span_ptr(original), 59, &final_size);
original = az_json_string_unescape(original, original);
original = az_span_slice(original, 0, final_size);
assert_int_equal(AZ_OK, result);
assert_true(az_span_is_content_equal(expected, original));
_az_span_free(&original);
}
@ -3317,40 +3219,11 @@ static void test_az_json_string_unescape_same_buffer(void** state)
strdup("Hello \\b My \\f Name \\n Is \\r Doctor \\t Green \\\\ Thumb"));
az_span expected = AZ_SPAN_FROM_STR("Hello \b My \f Name \n Is \r Doctor \t Green \\ Thumb");
int final_size;
az_result result
= az_json_string_unescape(original, (char*)az_span_ptr(original), 59, &final_size);
original = az_json_string_unescape(original, original);
original = az_span_slice(original, 0, final_size);
assert_int_equal(AZ_OK, result);
assert_true(az_span_is_content_equal(expected, original));
_az_span_free(&original);
}
// fake escapes
{
az_span original = az_span_create_from_str(strdup("\\9"));
int final_size;
az_result result
= az_json_string_unescape(original, (char*)az_span_ptr(original), 59, &final_size);
assert_int_equal(AZ_ERROR_UNEXPECTED_CHAR, result);
_az_span_free(&original);
}
// malformed escapes
{
az_span original = az_span_create_from_str(strdup("abcd\\"));
int final_size;
az_result result
= az_json_string_unescape(original, (char*)az_span_ptr(original), 59, &final_size);
assert_int_equal(AZ_ERROR_UNEXPECTED_END, result);
_az_span_free(&original);
}
}
int test_az_json()

Просмотреть файл

@ -1,7 +1,7 @@
{
"name": "azure-sdk-for-c",
"version": "1.0.0",
"builtin-baseline": "f0aa678b7471497f1adedcc99f40e1599ad22f69",
"builtin-baseline": "94ce0dab56f4d8ba6bd631ba59ed682b02d45c46",
"dependencies": [
{
"name": "curl"
@ -12,11 +12,5 @@
{
"name": "cmocka"
}
],
"overrides": [
{
"name": "zlib",
"version": "1.2.12#2"
}
]
}