Skip to content

Commit d032253

Browse files
committed
added support for c-style hex numbers to be exported as strings
1 parent e2f3766 commit d032253

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/Microsoft.OpenApi/Writers/SpecialCharacterStringExtensions.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,10 @@ internal static string GetYamlCompatibleString(this string input)
187187
return $"'{input}'";
188188
}
189189

190-
// If string can be mistaken as a number, a boolean, or a timestamp,
191-
// wrap it in quote to indicate that this is indeed a string, not a number, a boolean, or a timestamp
190+
// If string can be mistaken as a number, c-style hexadecimal notation, a boolean, or a timestamp,
191+
// wrap it in quote to indicate that this is indeed a string, not a number, c-style hexadecimal notation, a boolean, or a timestamp
192192
if (decimal.TryParse(input, NumberStyles.Float, CultureInfo.InvariantCulture, out var _) ||
193+
IsHexadecimalNotation(input) ||
193194
bool.TryParse(input, out var _) ||
194195
DateTime.TryParse(input, out var _))
195196
{
@@ -225,5 +226,10 @@ internal static string GetJsonCompatibleString(this string value)
225226

226227
return $"\"{value}\"";
227228
}
229+
230+
internal static bool IsHexadecimalNotation(string input)
231+
{
232+
return input.StartsWith("0x") && int.TryParse(input.Substring(2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var _);
233+
}
228234
}
229235
}

0 commit comments

Comments
 (0)