From 0cf630d2b9644be44ced5dcd5ef50d0aaeaba0b4 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Thu, 23 Mar 2023 02:03:23 -0700 Subject: [PATCH] Fix parsing of inet[/127.0.0.1:9200] (#49) * sniffer: fix parsing of inet[hostname/ip:port] Prior to commit 53f37cb7ef147ab51a04a4562885e234f9e8bbf1, publish_address of the format `inet[hostname/ip:port]` worked correctly. When the sniffer code was refactored, this format broke, and is an easy fix to restore. Fixes: https://github.com/elastic/elastic-transport-ruby/issues/48 Signed-off-by: Robin H. Johnson * sniffer: fix empty hostname like inet[/127.0.0.1:9200] Fixes: https://github.com/elastic/elastic-transport-ruby/issues/48 Signed-off-by: Robin H. Johnson --------- Signed-off-by: Robin H. Johnson --- lib/elastic/transport/transport/sniffer.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/elastic/transport/transport/sniffer.rb b/lib/elastic/transport/transport/sniffer.rb index af4d244f..8ab1f56a 100644 --- a/lib/elastic/transport/transport/sniffer.rb +++ b/lib/elastic/transport/transport/sniffer.rb @@ -76,7 +76,12 @@ def perform_sniff_request end def parse_publish_address(publish_address) - # publish_address is in the format hostname/ip:port + # publish_address is in the format: + # - hostname/ip:port + # - inet[hostname/ip:port] + publish_address = publish_address[5..-2] if publish_address =~ /^inet\[.*\]$/ + # If hostname is empty. + publish_address = publish_address[1..] if publish_address =~ /^\// if publish_address =~ /\// parts = publish_address.partition('/') [ parts[0], parse_address_port(parts[2])[1] ]