Kaynağa Gözat

feat(core): add configure_with method and specify utf-8 encoding

Add configure_with<T>() method to WebApplication for transient scoped
dependency injection resolution. Explicitly specify utf-8 encoding in
Html.Doc.read_memory calls across markup components for consistent
character encoding handling.
Billy Barrow 1 hafta önce
ebeveyn
işleme
42a952c7c8

+ 7 - 0
src/Core/WebApplication.vala

@@ -80,6 +80,13 @@ namespace Astralis {
             return container.register_module<T>(construct_func);
         }
 
+        public T configure_with<T>() throws Error {
+            var scope = container.create_transient_scope();
+            scope.register_local_scoped<WebApplication>(() => this);
+            var registration = scope.register_local_transient<T>();
+            return (T) scope.resolve_registration(registration);
+        }
+
         public void use_compression() {
             add_component<GzipCompressor>();
             add_component<ZstdCompressor>();

+ 2 - 2
src/Markup/MarkupDocument.vala

@@ -88,7 +88,7 @@ namespace Astralis {
                 Html.ParserOption.NONET);
             
             char[] buffer = html.to_utf8();
-            doc = Html.Doc.read_memory(buffer, buffer.length, "", null, options);
+            doc = Html.Doc.read_memory(buffer, buffer.length, "", "utf-8", options);
 
             if (doc == null) {
                 throw new MarkupError.PARSE_ERROR("Failed to parse HTML document");
@@ -278,7 +278,7 @@ namespace Astralis {
         /// </summary>
         public HttpResult to_result(StatusCode status = StatusCode.OK) {
             return new HttpStringResult(this.to_html(), status)
-                .set_header("Content-Type", "text/html; charset=UTF-8");
+                .set_header("Content-Type", "text/html; charset=utf-8");
         }
 
         /// <summary>

+ 2 - 2
src/Markup/MarkupNode.vala

@@ -327,7 +327,7 @@ namespace Astralis {
                 
                 string wrapped = "<div>" + value + "</div>";
                 char[] buffer = wrapped.to_utf8();
-                var temp_doc = Html.Doc.read_memory(buffer, buffer.length, "", null, options);
+                var temp_doc = Html.Doc.read_memory(buffer, buffer.length, "", "utf-8", options);
                 if (temp_doc == null) {
                     return;
                 }
@@ -393,7 +393,7 @@ namespace Astralis {
                 
                 string wrapped = "<div>" + value + "</div>";
                 char[] buffer = wrapped.to_utf8();
-                var temp_doc = Html.Doc.read_memory(buffer, buffer.length, "", null, options);
+                var temp_doc = Html.Doc.read_memory(buffer, buffer.length, "", "utf-8", options);
                 if (temp_doc == null) {
                     return;
                 }

+ 2 - 2
src/Markup/MarkupTemplate.vala

@@ -63,13 +63,13 @@ namespace Astralis {
                     Html.ParserOption.NONET);
                 
                 char[] buffer = html.to_utf8();
-                cached_doc = Html.Doc.read_memory(buffer, buffer.length, "", null, options);
+                cached_doc = Html.Doc.read_memory(buffer, buffer.length, "", "utf-8", options);
                 
                 if (cached_doc == null) {
                     // Try parsing as a fragment wrapped in a basic structure
                     string wrapped = "<!DOCTYPE html><html><head><meta charset=\"UTF-8\"/></head><body>%s</body></html>".printf(html);
                     char[] wrapped_buffer = wrapped.to_utf8();
-                    cached_doc = Html.Doc.read_memory(wrapped_buffer, wrapped_buffer.length, "", null, options);
+                    cached_doc = Html.Doc.read_memory(wrapped_buffer, wrapped_buffer.length, "", "utf-8", options);
                 }
                 
                 if (cached_doc == null) {