[VM/Service] Fix package generator
package:markdown was updated to follow CommonMark's rules for encoding
certain special characters as HTMLEntities.
See https://github.com/chenzhiguang/fork-markdown/blob/43bafebbe8534ed3b6e732b5bbf6f427202d6828/lib/src/util.dart#L15
This CL updates the package:vm_service generators to handle these
changes.
Change-Id: I4e2e4c1c800a44ff1f3b9e7e163d60876cd6b013
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/272522
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Derek Xu <derekx@google.com>
diff --git a/pkg/vm_service/lib/src/vm_service.dart b/pkg/vm_service/lib/src/vm_service.dart
index 132563c..7b4745f 100644
--- a/pkg/vm_service/lib/src/vm_service.dart
+++ b/pkg/vm_service/lib/src/vm_service.dart
@@ -937,10 +937,10 @@
/// their resolved (or absolute) paths. For example, URIs passed to this RPC
/// are mapped in the following ways:
///
- /// - `dart:io` -> `org-dartlang-sdk:///sdk/lib/io/io.dart`
- /// - `package:test/test.dart` ->
+ /// - `dart:io` -> `org-dartlang-sdk:///sdk/lib/io/io.dart`
+ /// - `package:test/test.dart` ->
/// `file:///$PACKAGE_INSTALLATION_DIR/lib/test.dart`
- /// - `file:///foo/bar/bazz.dart` -> `file:///foo/bar/bazz.dart`
+ /// - `file:///foo/bar/bazz.dart` -> `file:///foo/bar/bazz.dart`
///
/// If a URI is not known, the corresponding entry in the [UriList] response
/// will be `null`.
@@ -956,10 +956,10 @@
/// unresolved paths. For example, URIs passed to this RPC are mapped in the
/// following ways:
///
- /// - `org-dartlang-sdk:///sdk/lib/io/io.dart` -> `dart:io`
- /// - `file:///$PACKAGE_INSTALLATION_DIR/lib/test.dart` ->
+ /// - `org-dartlang-sdk:///sdk/lib/io/io.dart` -> `dart:io`
+ /// - `file:///$PACKAGE_INSTALLATION_DIR/lib/test.dart` ->
/// `package:test/test.dart`
- /// - `file:///foo/bar/bazz.dart` -> `file:///foo/bar/bazz.dart`
+ /// - `file:///foo/bar/bazz.dart` -> `file:///foo/bar/bazz.dart`
///
/// If a URI is not known, the corresponding entry in the [UriList] response
/// will be `null`.
diff --git a/pkg/vm_service/tool/common/src_gen_common.dart b/pkg/vm_service/tool/common/src_gen_common.dart
index 1962c61..924a101 100644
--- a/pkg/vm_service/tool/common/src_gen_common.dart
+++ b/pkg/vm_service/tool/common/src_gen_common.dart
@@ -36,6 +36,20 @@
String lowerTitleCase(String str) =>
str.substring(0, 1).toLowerCase() + str.substring(1);
+/// Certain special characters are encoded as HTML entities by the Markdown
+/// parser, this function changes those HTML entities back into the characters
+/// they represent.
+String replaceHTMLEntities(String text) {
+ return text
+ // TODO(derekx): Remove the line handling single-quotes once the
+ // package:markdown dep is bumped to ^7.0.0.
+ .replaceAll(''', "'")
+ .replaceAll('"', '"')
+ .replaceAll('&', '&')
+ .replaceAll('<', '<')
+ .replaceAll('>', '>');
+}
+
String joinLast(Iterable<String> strs, String join, [String? last]) {
if (strs.isEmpty) return '';
List list = strs.toList();
diff --git a/pkg/vm_service/tool/dart/generate_dart.dart b/pkg/vm_service/tool/dart/generate_dart.dart
index 6aeae39..3ac0aa5 100644
--- a/pkg/vm_service/tool/dart/generate_dart.dart
+++ b/pkg/vm_service/tool/dart/generate_dart.dart
@@ -468,11 +468,9 @@
String? get docs => null;
void _parse(String name, String definition, [String? docs]) {
- name = name.trim();
- definition = definition.trim();
- // clean markdown introduced changes
- definition = definition.replaceAll('<', '<').replaceAll('>', '>');
- if (docs != null) docs = docs.trim();
+ name = replaceHTMLEntities(name.trim());
+ definition = replaceHTMLEntities(definition.trim());
+ if (docs != null) docs = replaceHTMLEntities(docs.trim());
if (definition.startsWith('class ')) {
types.add(Type(this, name, definition, docs));
diff --git a/pkg/vm_service/tool/java/generate_java.dart b/pkg/vm_service/tool/java/generate_java.dart
index d533c5e..4f81dcd5 100644
--- a/pkg/vm_service/tool/java/generate_java.dart
+++ b/pkg/vm_service/tool/java/generate_java.dart
@@ -308,11 +308,9 @@
}
void _parse(String name, String definition, [String? docs]) {
- name = name.trim();
- definition = definition.trim();
- // clean markdown introduced changes
- definition = definition.replaceAll('<', '<').replaceAll('>', '>');
- if (docs != null) docs = docs.trim();
+ name = replaceHTMLEntities(name.trim());
+ definition = replaceHTMLEntities(definition.trim());
+ if (docs != null) docs = replaceHTMLEntities(docs.trim());
if (definition.startsWith('class ')) {
types.add(Type(this, scriptLocation, name, definition, docs));