mirror of https://github.com/LemmyNet/lemmy.git
* Count chars, not bytes for max title length (fixes #4366) * fix api testpost-view-secondary-sort
parent
9240a653c0
commit
1be7dbde33
|
@ -76,7 +76,12 @@ test("Create a post", async () => {
|
||||||
throw "Missing beta community";
|
throw "Missing beta community";
|
||||||
}
|
}
|
||||||
|
|
||||||
let postRes = await createPost(alpha, betaCommunity.community.id);
|
let postRes = await createPost(
|
||||||
|
alpha,
|
||||||
|
betaCommunity.community.id,
|
||||||
|
"https://example.com/",
|
||||||
|
"แแจแจ แแแฎแแแก แแ แแแก แแแฃแงแแแแแแแแ แแแแแแแแแกแฃแคแแแก แแแแแแแแฃแแ แแแแแแแแก แขแแแแแ แ",
|
||||||
|
);
|
||||||
expect(postRes.post_view.post).toBeDefined();
|
expect(postRes.post_view.post).toBeDefined();
|
||||||
expect(postRes.post_view.community.local).toBe(false);
|
expect(postRes.post_view.community.local).toBe(false);
|
||||||
expect(postRes.post_view.creator.local).toBe(true);
|
expect(postRes.post_view.creator.local).toBe(true);
|
||||||
|
|
|
@ -202,10 +202,10 @@ export async function setupLogins() {
|
||||||
export async function createPost(
|
export async function createPost(
|
||||||
api: LemmyHttp,
|
api: LemmyHttp,
|
||||||
community_id: number,
|
community_id: number,
|
||||||
// use example.com for consistent title and embed description
|
|
||||||
url: string = "https://example.com/",
|
url: string = "https://example.com/",
|
||||||
|
// use example.com for consistent title and embed description
|
||||||
|
name: string = randomString(5),
|
||||||
): Promise<PostResponse> {
|
): Promise<PostResponse> {
|
||||||
let name = randomString(5);
|
|
||||||
let body = randomString(10);
|
let body = randomString(10);
|
||||||
let form: CreatePost = {
|
let form: CreatePost = {
|
||||||
name,
|
name,
|
||||||
|
|
|
@ -147,7 +147,7 @@ pub fn is_valid_matrix_id(matrix_id: &str) -> LemmyResult<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_valid_post_title(title: &str) -> LemmyResult<()> {
|
pub fn is_valid_post_title(title: &str) -> LemmyResult<()> {
|
||||||
let length = title.trim().len();
|
let length = title.trim().chars().count();
|
||||||
let check = (3..=200).contains(&length) && !has_newline(title);
|
let check = (3..=200).contains(&length) && !has_newline(title);
|
||||||
if !check {
|
if !check {
|
||||||
Err(LemmyErrorType::InvalidPostTitle.into())
|
Err(LemmyErrorType::InvalidPostTitle.into())
|
||||||
|
@ -380,6 +380,10 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_valid_post_title() {
|
fn test_valid_post_title() {
|
||||||
assert!(is_valid_post_title("Post Title").is_ok());
|
assert!(is_valid_post_title("Post Title").is_ok());
|
||||||
|
assert!(is_valid_post_title(
|
||||||
|
"แแจแจ แแแฎแแแก แแ แแแก แแแฃแงแแแแแแแแ แแแแแแแแแกแฃแคแแแก แแแแแแแแฃแแ แแแแแแแแก แขแแแแแ แ"
|
||||||
|
)
|
||||||
|
.is_ok());
|
||||||
assert!(is_valid_post_title(" POST TITLE ๐๐๐๐๐").is_ok());
|
assert!(is_valid_post_title(" POST TITLE ๐๐๐๐๐").is_ok());
|
||||||
assert!(is_valid_post_title("\n \n \n \n ").is_err()); // tabs/spaces/newlines
|
assert!(is_valid_post_title("\n \n \n \n ").is_err()); // tabs/spaces/newlines
|
||||||
}
|
}
|
||||||
|
|
Loadingโฆ
Reference in New Issue