brusdev commented on code in PR #170:
URL: https://github.com/apache/artemis-console/pull/170#discussion_r2828272682
##########
artemis-console-extension/artemis-extension/packages/artemis-console-plugin/src/util/jmx.ts:
##########
@@ -28,16 +28,41 @@ const ADDRESS_COMPONENT = "component=addresses";
*
"127.0.0.1",component=addresses,address="q1",subcomponent=queues,routing-type="anycast",queue="q1"
*/
export function createQueueObjectName(brokerMBean: string, address: string,
routingType: string, queue: string): string {
- var queueMBeanName = queue;
- if(queueMBeanName.includes('\\')){
- //it may have a client id with /. in the name which is delimeted in
the mbean name
- queueMBeanName = queueMBeanName.replaceAll('\\', '\\\\');
- }
- return brokerMBean + ADDRESS_COMPONENT_PART + address +
ADDRESS_SUBCOMPONENT_PART + routingType.toLowerCase() + ADDRESS_TYPE_PART +
queueMBeanName + STRING_DELIMETER;
+ let addressMBeanName = mbeanQuote(address);
+ let queueMBeanName = mbeanQuote(queue);
+ return brokerMBean + ADDRESS_COMPONENT_PART + addressMBeanName +
ADDRESS_SUBCOMPONENT_PART + routingType.toLowerCase() + ADDRESS_TYPE_PART +
queueMBeanName + STRING_DELIMETER;
}
export function createAddressObjectName(brokerMBean: string, address: string) {
- return brokerMBean + ADDRESS_COMPONENT_PART + address + STRING_DELIMETER;
+ return brokerMBean + ADDRESS_COMPONENT_PART + mbeanQuote(address) +
STRING_DELIMETER;
+}
+
+function mbeanQuote(value: string): string {
+ let res = value
+ // it may have a client id with \. in the name which is delimited in the
mbean name
+ // according to javax.management.ObjectName.quote() javadoc, we have to
replace:
+ res = res.replaceAll('\\', '\\\\');
+ res = res.replaceAll('*', '\\*');
+ res = res.replaceAll('"', '\\"');
+ res = res.replaceAll('?', '\\?');
+ return res
+}
+
+/**
+ * This function should behave like `ObjectName.unquote` for quoted values and
should not change the value
+ * when it's not quoted
+ * @param value
+ */
+export function unquote(value: string): string {
+ if (!value || !value.startsWith('"') || !value.endsWith('"')) {
+ return value
+ }
+ let res = value.substring(1, value.length - 1);
+ res = res.replaceAll('\\"', '"');
+ res = res.replaceAll('\\*', '*');
+ res = res.replaceAll('\\?', '?');
+ res = res.replaceAll('\\\\', '\\');
+ return res
}
Review Comment:
what about aligning the function name to the real purpose, i.e. `export
function unescape(value: string): string {` to avoid confusion?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]