diff options
Diffstat (limited to 'internal/processing')
| -rw-r--r-- | internal/processing/account/create.go | 3 | ||||
| -rw-r--r-- | internal/processing/account/update.go | 5 | ||||
| -rw-r--r-- | internal/processing/status/create.go | 3 | ||||
| -rw-r--r-- | internal/processing/status/create_test.go | 34 | 
4 files changed, 40 insertions, 5 deletions
diff --git a/internal/processing/account/create.go b/internal/processing/account/create.go index 1a172b865..32a59d1ef 100644 --- a/internal/processing/account/create.go +++ b/internal/processing/account/create.go @@ -34,8 +34,7 @@ import (  // Create processes the given form for creating a new account,  // returning an oauth token for that account if successful.  // -// Fields on the form should have already been validated by the -// caller, before this function is called. +// Precondition: the form's fields should have already been validated and normalized by the caller.  func (p *Processor) Create(  	ctx context.Context,  	appToken oauth2.TokenInfo, diff --git a/internal/processing/account/update.go b/internal/processing/account/update.go index 01c62d7e3..f75b3c8d9 100644 --- a/internal/processing/account/update.go +++ b/internal/processing/account/update.go @@ -222,10 +222,11 @@ func (p *Processor) Update(ctx context.Context, account *gtsmodel.Account, form  	if form.Source != nil {  		if form.Source.Language != nil { -			if err := validate.Language(*form.Source.Language); err != nil { +			language, err := validate.Language(*form.Source.Language) +			if err != nil {  				return nil, gtserror.NewErrorBadRequest(err)  			} -			account.Language = *form.Source.Language +			account.Language = language  		}  		if form.Source.Sensitive != nil { diff --git a/internal/processing/status/create.go b/internal/processing/status/create.go index 2d9c3a196..36842ee07 100644 --- a/internal/processing/status/create.go +++ b/internal/processing/status/create.go @@ -37,6 +37,8 @@ import (  )  // Create processes the given form to create a new status, returning the api model representation of that status if it's OK. +// +// Precondition: the form's fields should have already been validated and normalized by the caller.  func (p *Processor) Create(ctx context.Context, account *gtsmodel.Account, application *gtsmodel.Application, form *apimodel.AdvancedStatusCreateForm) (*apimodel.Status, gtserror.WithCode) {  	accountURIs := uris.GenerateURIsForAccount(account.Username)  	thisStatusID := id.NewULID() @@ -55,7 +57,6 @@ func (p *Processor) Create(ctx context.Context, account *gtsmodel.Account, appli  		ContentWarning:           text.SanitizePlaintext(form.SpoilerText),  		ActivityStreamsType:      ap.ObjectNote,  		Sensitive:                &sensitive, -		Language:                 form.Language,  		CreatedWithApplicationID: application.ID,  		Text:                     form.Status,  	} diff --git a/internal/processing/status/create_test.go b/internal/processing/status/create_test.go index 2a797516d..2c86e5a29 100644 --- a/internal/processing/status/create_test.go +++ b/internal/processing/status/create_test.go @@ -208,6 +208,40 @@ func (suite *StatusCreateTestSuite) TestProcessMediaDescriptionTooShort() {  	suite.Nil(apiStatus)  } +func (suite *StatusCreateTestSuite) TestProcessLanguageWithScriptPart() { +	ctx := context.Background() + +	creatingAccount := suite.testAccounts["local_account_1"] +	creatingApplication := suite.testApplications["application_1"] + +	statusCreateForm := &apimodel.AdvancedStatusCreateForm{ +		StatusCreateRequest: apimodel.StatusCreateRequest{ +			Status:      "你好世界", // hello world +			MediaIDs:    []string{}, +			Poll:        nil, +			InReplyToID: "", +			Sensitive:   false, +			SpoilerText: "", +			Visibility:  apimodel.VisibilityPublic, +			ScheduledAt: "", +			Language:    "zh-Hans", +			ContentType: apimodel.StatusContentTypePlain, +		}, +		AdvancedVisibilityFlagsForm: apimodel.AdvancedVisibilityFlagsForm{ +			Federated: nil, +			Boostable: nil, +			Replyable: nil, +			Likeable:  nil, +		}, +	} + +	apiStatus, err := suite.status.Create(ctx, creatingAccount, creatingApplication, statusCreateForm) +	suite.NoError(err) +	suite.NotNil(apiStatus) + +	suite.Equal("zh-Hans", *apiStatus.Language) +} +  func TestStatusCreateTestSuite(t *testing.T) {  	suite.Run(t, new(StatusCreateTestSuite))  }  | 
