Skip to content

Commit 4cd6eb5

Browse files
Merge pull request restsharp#1513 from liquidboy/issue-1480
fix restsharp#1480 - ToCamelCase broken for a single word with multiple upperc…
2 parents f9aa955 + 1b7dd95 commit 4cd6eb5

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/RestSharp/Extensions/StringExtensions.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,12 @@ public static string ToPascalCase(this string text, bool removeUnderscores, Cult
222222

223223
string CaseWord(string word)
224224
{
225-
var restOfWord = word.Substring(1).ToLower(culture);
225+
var restOfWord = word.Substring(1);
226226
var firstChar = char.ToUpper(word[0], culture);
227227

228+
if (restOfWord.IsUpperCase())
229+
restOfWord = restOfWord.ToLower(culture);
230+
228231
return string.Concat(firstChar, restOfWord);
229232
}
230233
}
@@ -274,6 +277,13 @@ public static string AddDashes(this string pascalCasedWord)
274277
"-"
275278
);
276279

280+
/// <summary>
281+
/// Checks to see if a string is all uppper case
282+
/// </summary>
283+
/// <param name="inputString">String to check</param>
284+
/// <returns>bool</returns>
285+
public static bool IsUpperCase(this string inputString) => IsUpperCaseRegex.IsMatch(inputString);
286+
277287
/// <summary>
278288
/// Add an underscore prefix to a pascal-cased string
279289
/// </summary>

test/RestSharp.Tests/StringExtensionsTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ public void ToPascalCase(string start, bool removeUnderscores, string finish)
6666
Assert.AreEqual(finish, result);
6767
}
6868

69+
[Test, TestCase("DueDate", "dueDate"), TestCase("ID", "id"), TestCase("IDENTIFIER", "identifier"), TestCase("primaryId", "primaryId"), TestCase("A", "a"), TestCase("ThisIsATest", "thisIsATest")]
70+
public void ToCamelCase(string start, string finish)
71+
{
72+
var result = start.ToCamelCase(CultureInfo.InvariantCulture);
73+
74+
Assert.AreEqual(finish, result);
75+
}
76+
6977
[Test]
7078
public void Does_not_throw_on_invalid_encoding()
7179
{

0 commit comments

Comments
 (0)