escape.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. Copyright 2014 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package strings
  14. import (
  15. "strings"
  16. )
  17. // EscapePluginName converts a plugin name in the format
  18. // vendor/pluginname into a proper ondisk vendor~pluginname plugin directory
  19. // format.
  20. func EscapePluginName(in string) string {
  21. return strings.Replace(in, "/", "~", -1)
  22. }
  23. // EscapeQualifiedPluginName converts a plugin directory name in the format
  24. // vendor~pluginname into a proper vendor/pluginname.
  25. func UnescapePluginName(in string) string {
  26. return strings.Replace(in, "~", "/", -1)
  27. }
  28. // EscapeQualifiedNameForDisk converts a plugin name, which might contain a / into a
  29. // string that is safe to use on-disk. This assumes that the input has already
  30. // been validates as a qualified name. we use "~" rather than ":" here in case
  31. // we ever use a filesystem that doesn't allow ":".
  32. func EscapeQualifiedNameForDisk(in string) string {
  33. return strings.Replace(in, "/", "~", -1)
  34. }
  35. // UnescapeQualifiedNameForDisk converts an escaped plugin name (as per EscapeQualifiedNameForDisk)
  36. // back to its normal form. This assumes that the input has already been
  37. // validates as a qualified name.
  38. func UnescapeQualifiedNameForDisk(in string) string {
  39. return strings.Replace(in, "~", "/", -1)
  40. }