Skip to content
This repository has been archived by the owner on Feb 29, 2020. It is now read-only.

Commit

Permalink
[client][managed][offline] Relax queryId restrictions #521
Browse files Browse the repository at this point in the history
  • Loading branch information
hasankhan committed Dec 4, 2014
1 parent 5a06901 commit 3e2f645
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 13 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@
<value>The store is already initialized.</value>
</data>
<data name="MobileServiceSyncTable_InvalidQueryId" xml:space="preserve">
<value>The query id must start with a letter and can contain only letters, digits, hyphen or underscore.</value>
<value>The query id must not contain pipe character and should be less than 50 characters in length.</value>
</data>
<data name="MobileServiceSyncTable_IncrementalPullWithOrderNotAllowed" xml:space="preserve">
<value>Incremental pull query must not have orderby clause.</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Microsoft.WindowsAzure.MobileServices.Sync
{
internal class MobileServiceSyncTable : IMobileServiceSyncTable
{
private static readonly Regex queryIdRegex = new Regex("^[a-zA-Z][a-zA-Z0-9_-]{0,24}$");
private static readonly Regex queryIdRegex = new Regex("^[^|]{0,50}$");
private MobileServiceSyncContext syncContext;

public MobileServiceClient MobileServiceClient { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ public class MobileServiceSyncTableTests
[TestMethod]
public void ValidateQueryId_Throws_OnInvalidId()
{
var testCases = new[] { "-myitems", "_myitems", "|myitems", "s|myitems", "asdf@#$!@" };
var testCases = new[] { "|myitems", "s|myitems", "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" };
foreach (var queryId in testCases)
{
var ex = AssertEx.Throws<ArgumentException>(() => MobileServiceSyncTable.ValidateQueryId(queryId));
Assert.AreEqual(ex.Message, "The query id must start with a letter and can contain only letters, digits, hyphen or underscore.");
Assert.AreEqual(ex.Message, "The query id must not contain pipe character and should be less than 50 characters in length.");
}
}

[TestMethod]
public void ValidateQueryId_Succeeds_OnValidId()
{
var testCases = new[] { "myitems1", "myItems_yourItems1", "my-items123" };
var testCases = new[] { "myitems1", "myItems_yourItems1", "my-items123", "-myitems", "_myitems", "asdf@#$!/:^" };
foreach (var queryId in testCases)
{
MobileServiceSyncTable.ValidateQueryId(queryId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -821,9 +821,7 @@ public async Task PullAsync_Throws_WhenQueryIdIsInvalid()

IMobileServiceSyncTable<ToDoWithStringId> table = service.GetSyncTable<ToDoWithStringId>();

await ThrowsAsync<ArgumentException>(() => table.PullAsync("2asdf", table.CreateQuery(), CancellationToken.None));
await ThrowsAsync<ArgumentException>(() => table.PullAsync("asd_@#234", table.CreateQuery(), CancellationToken.None));
await ThrowsAsync<ArgumentException>(() => table.PullAsync("asd_^^234", table.CreateQuery(), CancellationToken.None));
await ThrowsAsync<ArgumentException>(() => table.PullAsync("2as|df", table.CreateQuery(), CancellationToken.None));
}

private async Task TestPullQueryOverrideThrows(IDictionary<string, string> parameters, string errorMessage)
Expand Down Expand Up @@ -926,9 +924,7 @@ public async Task PurgeAsync_Throws_WhenQueryIdIsInvalid()

IMobileServiceSyncTable<ToDoWithStringId> table = service.GetSyncTable<ToDoWithStringId>();

await ThrowsAsync<ArgumentException>(() => table.PurgeAsync("2asdf", table.CreateQuery(), CancellationToken.None));
await ThrowsAsync<ArgumentException>(() => table.PurgeAsync("asd_@#234", table.CreateQuery(), CancellationToken.None));
await ThrowsAsync<ArgumentException>(() => table.PurgeAsync("asd_^^234", table.CreateQuery(), CancellationToken.None));
await ThrowsAsync<ArgumentException>(() => table.PurgeAsync("2as|df", table.CreateQuery(), CancellationToken.None));
}

[AsyncTestMethod]
Expand Down

0 comments on commit 3e2f645

Please sign in to comment.