Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/Twilio/Types/App.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;

namespace Twilio.Types
{
/// <summary>
/// App Endpoint
/// </summary>
public class App : IEndpoint
{
public const string PREFIX = "app:";

private readonly string _app;

/// <summary>
/// Create new app
/// </summary>
/// <param name="app">App name</param>
public App(string app)
{
if (string.IsNullOrEmpty(app))
{
throw new ArgumentException("Parameter 'app' cannot be null or empty.", nameof(app));
}

if (!app.ToLower().StartsWith(PREFIX))
{
app = PREFIX + app;
}
Comment on lines +25 to +28
Copy link

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prefix check uses app.ToLower().StartsWith(PREFIX) but PREFIX is lowercase 'app:'. This means inputs like 'APP:test' or 'App:test' will incorrectly have the prefix added again, resulting in 'app:APP:test' or 'app:App:test'. Use case-insensitive comparison: !app.StartsWith(PREFIX, StringComparison.OrdinalIgnoreCase)

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is working fine, check again.
app= "hello", outcome(_app) = "app:hello"
app= "app:hello", outcome(_app) = "app:hello"
app= "App:hello", outcome(_app) = "App:hello"


_app = app;
}

/// <summary>
/// Convert to string
/// </summary>
/// <returns>String representation</returns>
public override string ToString()
{
return _app;
}
}
}
23 changes: 23 additions & 0 deletions test/Twilio.Test/Types/AppTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using NUnit.Framework;
using Twilio.Exceptions;
using Twilio.Types;

namespace Twilio.Tests.Types
{
[TestFixture]
public class AppTest
{
[Test]
public void TestToString()
{
Assert.AreEqual("app:me", new App("me").ToString());
Assert.AreEqual("app:YOU", new App("YOU").ToString());
Assert.AreEqual("APP:HIM", new App("APP:HIM").ToString());
Assert.AreEqual("aPp:her", new App("aPp:her").ToString());
Assert.Throws<ArgumentException>(() => new App("").ToString());
Assert.AreEqual("app:AP12345?mycustomparam1=foo&mycustomparam2=bar", new App("app:AP12345?mycustomparam1=foo&mycustomparam2=bar").ToString());
Assert.AreEqual("app:AP12345?mycustomparam1=foo&mycustomparam2=bar", new App("AP12345?mycustomparam1=foo&mycustomparam2=bar").ToString());
}
}
}
Loading