mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 18:08:42 -05:00
(QENG-7530) Fix hostname_shorten regex
Prior to this commit the hostname_shorten regex wouldn't match the updated human readable hostnames because they contain dashes. This commit updates the regex to capture dashes in the hostname, and adds a few specs to verify that behavior.
This commit is contained in:
parent
2b5d9c0dd9
commit
625472df35
2 changed files with 3 additions and 1 deletions
|
|
@ -140,7 +140,7 @@ module Vmpooler
|
||||||
end
|
end
|
||||||
|
|
||||||
def hostname_shorten(hostname, domain=nil)
|
def hostname_shorten(hostname, domain=nil)
|
||||||
if domain && hostname =~ /^\w+\.#{domain}$/
|
if domain && hostname =~ /^[\w-]+\.#{domain}$/
|
||||||
hostname = hostname[/[^\.]+/]
|
hostname = hostname[/[^\.]+/]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ describe Vmpooler::API::Helpers do
|
||||||
['example.com', 'not-example.com', 'example.com'],
|
['example.com', 'not-example.com', 'example.com'],
|
||||||
['example.com', 'example.com', 'example.com'],
|
['example.com', 'example.com', 'example.com'],
|
||||||
['sub.example.com', 'example.com', 'sub'],
|
['sub.example.com', 'example.com', 'sub'],
|
||||||
|
['adjective-noun.example.com', 'example.com', 'adjective-noun'],
|
||||||
|
['abc123.example.com', 'example.com', 'abc123'],
|
||||||
['example.com', nil, 'example.com']
|
['example.com', nil, 'example.com']
|
||||||
].each do |hostname, domain, expected|
|
].each do |hostname, domain, expected|
|
||||||
it { expect(subject.hostname_shorten(hostname, domain)).to eq expected }
|
it { expect(subject.hostname_shorten(hostname, domain)).to eq expected }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue