diff options
| author | Devon <devonrutledge03@gmail.com> | 2025-04-14 13:09:04 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-14 12:09:04 -0700 |
| commit | 387deedac3b61dd133fb529dc941483bc021f386 (patch) | |
| tree | a895293925457cc9298438f8f65db50683c4dac8 /source/slang | |
| parent | 0f0818722268464775981520c2d6e975a9cf14fa (diff) | |
Fix User Attribute string reflection (#6799)
* Fix User Attribute string reflection
Fixes #6794
* Fix strings not being properly escaped
---------
Co-authored-by: Darren Wihandi <65404740+fairywreath@users.noreply.github.com>
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/slang')
| -rw-r--r-- | source/slang/slang-reflection-json.cpp | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/source/slang/slang-reflection-json.cpp b/source/slang/slang-reflection-json.cpp index 82e8e1e3f..a84536f20 100644 --- a/source/slang/slang-reflection-json.cpp +++ b/source/slang/slang-reflection-json.cpp @@ -295,7 +295,7 @@ static void emitUserAttributeJSON(PrettyWriter& writer, slang::UserAttribute* us } else if (auto str = userAttribute->getArgumentValueString(i, &bufSize)) { - writer.write(str, bufSize); + writer.writeEscapedString(UnownedStringSlice(str, bufSize)); } else writer << "\"invalid value\""; @@ -303,7 +303,7 @@ static void emitUserAttributeJSON(PrettyWriter& writer, slang::UserAttribute* us writer.dedent(); writer << "\n]\n"; writer.dedent(); - writer << "}\n"; + writer << "}"; } static void emitUserAttributes(PrettyWriter& writer, slang::TypeReflection* type) @@ -311,7 +311,8 @@ static void emitUserAttributes(PrettyWriter& writer, slang::TypeReflection* type auto attribCount = type->getUserAttributeCount(); if (attribCount) { - writer << ",\n\"userAttribs\": ["; + writer << ",\n\"userAttribs\": [\n"; + writer.indent(); for (unsigned int i = 0; i < attribCount; i++) { if (i > 0) @@ -319,7 +320,8 @@ static void emitUserAttributes(PrettyWriter& writer, slang::TypeReflection* type auto attrib = type->getUserAttributeByIndex(i); emitUserAttributeJSON(writer, attrib); } - writer << "]"; + writer.dedent(); + writer << "\n]"; } } static void emitUserAttributes(PrettyWriter& writer, slang::VariableReflection* var) @@ -327,7 +329,8 @@ static void emitUserAttributes(PrettyWriter& writer, slang::VariableReflection* auto attribCount = var->getUserAttributeCount(); if (attribCount) { - writer << ",\n\"userAttribs\": ["; + writer << ",\n\"userAttribs\": [\n"; + writer.indent(); for (unsigned int i = 0; i < attribCount; i++) { if (i > 0) @@ -335,7 +338,8 @@ static void emitUserAttributes(PrettyWriter& writer, slang::VariableReflection* auto attrib = var->getUserAttributeByIndex(i); emitUserAttributeJSON(writer, attrib); } - writer << "]"; + writer.dedent(); + writer << "\n]"; } } static void emitUserAttributes(PrettyWriter& writer, slang::FunctionReflection* func) @@ -343,7 +347,8 @@ static void emitUserAttributes(PrettyWriter& writer, slang::FunctionReflection* auto attribCount = func->getUserAttributeCount(); if (attribCount) { - writer << ",\n\"userAttribs\": ["; + writer << ",\n\"userAttribs\": [\n"; + writer.indent(); for (unsigned int i = 0; i < attribCount; i++) { if (i > 0) @@ -351,7 +356,8 @@ static void emitUserAttributes(PrettyWriter& writer, slang::FunctionReflection* auto attrib = func->getUserAttributeByIndex(i); emitUserAttributeJSON(writer, attrib); } - writer << "]"; + writer.dedent(); + writer << "\n]"; } } |
