From 53e7bbef79ed421ef675cdbf7287355b4af492da Mon Sep 17 00:00:00 2001 From: Fesenko-A <111450737+Fesenko-A@users.noreply.github.com> Date: Thu, 30 Apr 2026 11:49:23 +0300 Subject: [PATCH] add number parsing for JSON object entries --- Apps.Contentful/Apps.Contentful.csproj | 2 +- .../HtmlHelpers/EntryToJsonConverter.cs | 3 +++ Tests.Contentful/EntryActionsTests.cs | 4 ++-- Tests.Contentful/EntryTranslationTests.cs | 7 ++++-- .../TestFiles/Input/json_fields.html | 22 +++++++++++++++++++ 5 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 Tests.Contentful/TestFiles/Input/json_fields.html diff --git a/Apps.Contentful/Apps.Contentful.csproj b/Apps.Contentful/Apps.Contentful.csproj index c6c9006..2f09caf 100644 --- a/Apps.Contentful/Apps.Contentful.csproj +++ b/Apps.Contentful/Apps.Contentful.csproj @@ -6,7 +6,7 @@ enable Contentful The headless content management system - 1.8.15 + 1.8.16 Apps.Contentful diff --git a/Apps.Contentful/HtmlHelpers/EntryToJsonConverter.cs b/Apps.Contentful/HtmlHelpers/EntryToJsonConverter.cs index 4adfbb1..41d1cf4 100644 --- a/Apps.Contentful/HtmlHelpers/EntryToJsonConverter.cs +++ b/Apps.Contentful/HtmlHelpers/EntryToJsonConverter.cs @@ -364,6 +364,9 @@ private static JToken ParseValueFromNode(HtmlNode node) if (bool.TryParse(textValue, out var boolValue)) return JValue.FromObject(boolValue); + + if (decimal.TryParse(textValue, out var decimalValue)) + return JValue.FromObject(decimalValue); return JValue.FromObject(textValue); } diff --git a/Tests.Contentful/EntryActionsTests.cs b/Tests.Contentful/EntryActionsTests.cs index 4d7ad75..fdc073c 100644 --- a/Tests.Contentful/EntryActionsTests.cs +++ b/Tests.Contentful/EntryActionsTests.cs @@ -146,8 +146,8 @@ public async Task GetEntryLocalizableFieldsAsHtmlFile_WithoutReferenceEntries_Sh var entryActions = new EntryActions(InvocationContext, FileManager); var entryIdentifier = new DownloadContentInput() { - Environment = "dev", - ContentId = "70rcIvfhhD9VjLlMTA3YPz", + Environment = "master", + ContentId = "4phPDNKF6oE6x7bexnmgGS", Locale = "en-US" }; var request = new GetEntryAsHtmlRequest(); diff --git a/Tests.Contentful/EntryTranslationTests.cs b/Tests.Contentful/EntryTranslationTests.cs index ffb5ea0..4873273 100644 --- a/Tests.Contentful/EntryTranslationTests.cs +++ b/Tests.Contentful/EntryTranslationTests.cs @@ -23,8 +23,11 @@ public class EntryTranslationTests : TestBase public async Task Translate_standard_html_file() { var actions = new EntryActions(InvocationContext, FileManager); - await actions.SetEntryLocalizableFieldsFromHtmlFile(new Apps.Contentful.Models.Requests.Tags.UploadEntryRequest { Content = new FileReference { Name = "contentful-pseudo.html" }, Locale = "de" }); - + await actions.SetEntryLocalizableFieldsFromHtmlFile( + new Apps.Contentful.Models.Requests.Tags.UploadEntryRequest + { + Content = new FileReference { Name = "json_fields.html" }, Locale = "en-US" + }); } [TestMethod] diff --git a/Tests.Contentful/TestFiles/Input/json_fields.html b/Tests.Contentful/TestFiles/Input/json_fields.html new file mode 100644 index 0000000..5910033 --- /dev/null +++ b/Tests.Contentful/TestFiles/Input/json_fields.html @@ -0,0 +1,22 @@ + + + + + + + + + + + +
+
+
+
True
+
123.45
+
+
+
+ + \ No newline at end of file