Handle special characters in event names #1
@ -22,6 +22,10 @@ func GenerateEventChannelName(eventName string, location string, dateTime time.T
 | 
				
			|||||||
	city := GetCityFromLocation(location)
 | 
						city := GetCityFromLocation(location)
 | 
				
			||||||
	year := dateTime.Year()
 | 
						year := dateTime.Year()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Remove special characters
 | 
				
			||||||
 | 
						eventName = regexp.MustCompile(`[^a-zA-Z0-9 ]+`).ReplaceAllString(eventName, "")
 | 
				
			||||||
 | 
						eventName = strings.Trim(eventName, " ")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	channel := fmt.Sprint(month, "-", day, city, "-", eventName, "-", year)
 | 
						channel := fmt.Sprint(month, "-", day, city, "-", eventName, "-", year)
 | 
				
			||||||
	channel = strings.ReplaceAll(channel, " ", "-")
 | 
						channel = strings.ReplaceAll(channel, " ", "-")
 | 
				
			||||||
	channel = strings.ToLower(channel)
 | 
						channel = strings.ToLower(channel)
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										32
									
								
								core/channel_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								core/channel_test.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,32 @@
 | 
				
			|||||||
 | 
					package core
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/stretchr/testify/assert"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestGenerateEventChannelName(t *testing.T) {
 | 
				
			||||||
 | 
						assert := assert.New(t)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Test Valid Address
 | 
				
			||||||
 | 
						channelName := GenerateEventChannelName("Hello World", "1234 Place Rd, Ann Arbor, MI 00000", time.Date(2022, time.January, 5, 0, 0, 0, 0, time.UTC))
 | 
				
			||||||
 | 
						assert.Equal("jan-5-ann-arbor-hello-world-2022", channelName)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Test Unparsable
 | 
				
			||||||
 | 
						// lmanley: Note it'd be nice to expand support for this
 | 
				
			||||||
 | 
						channelName = GenerateEventChannelName("Hello World", "Michigan Theater, Ann Arbor", time.Date(2022, time.January, 5, 0, 0, 0, 0, time.UTC))
 | 
				
			||||||
 | 
						assert.Equal("jan-5-hello-world-2022", channelName)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Test Short Location
 | 
				
			||||||
 | 
						channelName = GenerateEventChannelName("Hello World", "Monroe, MI", time.Date(2022, time.January, 5, 0, 0, 0, 0, time.UTC))
 | 
				
			||||||
 | 
						assert.Equal("jan-5-monroe-hello-world-2022", channelName)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Test Remote Event
 | 
				
			||||||
 | 
						channelName = GenerateEventChannelName("Hello World", RemoteLocation, time.Date(2022, time.January, 5, 0, 0, 0, 0, time.UTC))
 | 
				
			||||||
 | 
						assert.Equal("jan-5-online-hello-world-2022", channelName)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						channelName = GenerateEventChannelName("Hangout :)", "Quickly Livonia", time.Date(2022, time.January, 5, 0, 0, 0, 0, time.UTC))
 | 
				
			||||||
 | 
						assert.Equal("jan-5-quickly-livonia-hangout-2022", channelName)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user