Permalink
Browse files

Special-case 127.0.0.0/8 and ::1 loopbacks

  • Loading branch information...
michaelblyons committed May 5, 2017
1 parent 7b68d8e commit a67ff261813c3998201dabad6efc29add44b85f0
Showing with 27 additions and 0 deletions.
  1. +10 −0 hosts.tmLanguage
  2. +14 −0 hosts.tmLanguage.rb
  3. +3 −0 test/hosts
View
@@ -23,6 +23,16 @@
<string>#.*$</string>
</dict>
<!-- a different color for localhost -->
<dict>
<key>comment</key>
<string>Loopback address like 127.0.0.1</string>
<key>match</key>
<string>127(\.((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9][0-9])|[0-9])){3}|::1</string>
<key>name</key>
<string>support.type.built-in.loopback.hosts</string>
</dict>
<!-- a different color for local IP addresses -->
<dict>
<key>comment</key>
View
@@ -27,6 +27,8 @@
"192\\.168(\\.#{BYTE}){2}" # 192.169.x.x
].map { |addr| "(#{addr})" }.join('|')
LOOPBACK_IP_V4 = "127(\\.#{BYTE}){3}" # 127.x.x.x
# == IPv6 ==
# Luckily David M. Syzdek already did the hard work and we can use it here
@@ -52,6 +54,8 @@
"(#{SEGMENT}:){1,7}:", # 1:: 1:2:3:4:5:6:7::
].map { |variant| "(#{variant})" }.join('|')
LOOPBACK_IP_V6 = "::1"
# == render the tmLanguage file ==
# binding gives the template access to all local variables
@@ -85,6 +89,16 @@
<string>#.*$</string>
</dict>
<!-- a different color for localhost -->
<dict>
<key>comment</key>
<string>Loopback address like 127.0.0.1</string>
<key>match</key>
<string><%= LOOPBACK_IP_V4 %>|<%= LOOPBACK_IP_V6 %></string>
<key>name</key>
<string>support.type.built-in.loopback.hosts</string>
</dict>
<!-- a different color for local IP addresses -->
<dict>
<key>comment</key>
View
@@ -1,5 +1,6 @@
# localhost entries using IPv4 and IPv6
127.0.0.1 localhost.localdomain localhost
127.8.8.8 localhost.localdomain localhost
::1 localhost.localdomain localhost
# Private network IPs show in a different colour
@@ -20,6 +21,8 @@
# an IP in the public range should have different colour than private IP ranges
192.30.252.131 github.com
# an IP containing ::1 should not be partly highlighted as loopback
8::1 unassigned.arpa
# invalid IP addresses should not be highlighted as if they are valid
189.23.290.13 i.cannot.even

0 comments on commit a67ff26

Please sign in to comment.