idn_spec.rb 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe EmailHelper::Idn do
  4. let(:addresses) do
  5. [
  6. {
  7. unicode: 'John Doe 😃 <john.doe@doe😃.org>',
  8. ascii: 'John Doe 😃 <john.doe@xn--doe-5h33b.org>'
  9. },
  10. {
  11. unicode: 'John Doe 😃 john.doe@doe😃.org',
  12. ascii: 'John Doe 😃 john.doe@xn--doe-5h33b.org'
  13. },
  14. {
  15. unicode: 'John Doe 😃 john.doe@doe.org',
  16. ascii: 'John Doe 😃 john.doe@doe.org'
  17. },
  18. {
  19. unicode: 'John Doe 😃 <john.doe@doe.org>',
  20. ascii: 'John Doe 😃 <john.doe@doe.org>'
  21. },
  22. {
  23. unicode: 'John Doe 😃 <john.doe@doe😃.org> smiley man',
  24. ascii: 'John Doe 😃 <john.doe@xn--doe-5h33b.org> smiley man'
  25. },
  26. {
  27. unicode: 'John Doe 😃 john.doe@doe😃.org smiley man',
  28. ascii: 'John Doe 😃 john.doe@xn--doe-5h33b.org smiley man'
  29. },
  30. {
  31. unicode: 'John Doe 😃 john.doe@doe.org smiley man',
  32. ascii: 'John Doe 😃 john.doe@doe.org smiley man'
  33. },
  34. {
  35. unicode: 'John Doe 😃 <john.doe@doe.org> smiley man',
  36. ascii: 'John Doe 😃 <john.doe@doe.org> smiley man'
  37. },
  38. {
  39. unicode: '<john.doe@doe😃.org>',
  40. ascii: '<john.doe@xn--doe-5h33b.org>'
  41. },
  42. {
  43. unicode: 'john.doe@doe😃.org',
  44. ascii: 'john.doe@xn--doe-5h33b.org'
  45. },
  46. {
  47. unicode: 'john.doe@doe.org',
  48. ascii: 'john.doe@doe.org'
  49. },
  50. {
  51. unicode: '<john.doe@doe.org>',
  52. ascii: '<john.doe@doe.org>'
  53. },
  54. {
  55. unicode: 'John Doe 😃 john.doe@doe😃.org @smiley man',
  56. ascii: 'John Doe 😃 john.doe@xn--doe-5h33b.org @smiley man'
  57. }
  58. ]
  59. end
  60. describe '#to_ascii' do
  61. it 'converts correctly' do
  62. addresses.each do |address|
  63. expect(described_class.to_ascii(address[:unicode])).to eql(address[:ascii])
  64. end
  65. end
  66. end
  67. describe '#to_unicode' do
  68. it 'converts correctly' do
  69. addresses.each do |address|
  70. expect(described_class.to_unicode(address[:ascii])).to eql(address[:unicode])
  71. end
  72. end
  73. end
  74. end