Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Character encoding issue in updateConfig function #86

Open
thierry1129 opened this issue Jul 27, 2017 · 10 comments
Open

Character encoding issue in updateConfig function #86

thierry1129 opened this issue Jul 27, 2017 · 10 comments
Labels

Comments

@thierry1129
Copy link

So I use a very similar approach to create and modify jobs , and it works perfectly when I try to add Chinese or Japanese character in job description while creating a new job.

However when I modify an existing job and try to add a Chinese character in job description by calling the updateConfig function, there is only unreadable code in the description area after executing the function.

Any suggestions on how to resolve this? It really baffles me for the last few days since the CreateJob function works fine but the UpdateConfig function doesn't.

BTW thanks for resolving my last issue!

@thierry1129
Copy link
Author

@supereagle @bndr

@supereagle
Copy link
Collaborator

This is a bug. In my test, both CreateJob and UpdateConfig have this error. This is reasonable as they use the same request API. Not sure why CreateJob does not have this error in your test. Could you provide your example?

@supereagle supereagle added the bug label Jul 27, 2017
@thierry1129
Copy link
Author

Thanks for your reply. I extracted the config xml string of an existing job from jenkins server and pasted in my main method. When I used the string to create a new job, the description was fine, but when I used it to update the one that I just created, the description was filled with error code.

Here is a link to my code on go playground, and I have attached two screenshots of the jenkins job I created.

Is there anything that I could do on my end to fix this?

Thanks again.

https://play.golang.org/p/SsM5iK10Jo
newjobresult
updateresult

@supereagle
Copy link
Collaborator

@thierry1129 Thanks for your detail information.

As I can not open the go playground url: <h1>Unavailable For Legal Reasons</h1><p>If you believe this is in error, please <a href="https://golang.org/issue">file an issue</a>.</p>. Could you attach the code files?

@thierry1129
Copy link
Author

thierry1129 commented Jul 28, 2017

gojenkins test code.txt

Thanks for your reply and sorry for the inconvenience. I've attached my code here.

I just realized some of the formats(like line breaks) are lost in txt file, so here is another copy in docx.

gojenkins test code docx.docx

@chenliejun
Copy link

As I got the same problem,does there any alternative solution?thanks!
@thierry1129 @supereagle @bndr

@Leonwenbin
Copy link

Has anyone solved this problem?

@nxk88998
Copy link

nxk88998 commented Feb 20, 2024

我也遇到了这个问题
config = fmt.Sprintf(<?xml version="1.0" encoding="UTF-8"?> <flow-definition plugin="workflow-job@2.31"> <description></description> <keepDependencies>false</keepDependencies> <properties/> <definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition" plugin="workflow-cps@2.50"> <script> 测试 </script> <sandbox>true</sandbox> </definition> <triggers/> <disabled>false</disabled> </flow-definition>)
job.UpdateConfig(ctx, config)

测试 >> æµ�è¯

@nxk88998
Copy link

有没有人解决这个问题?

都卡住了

@nxk88998
Copy link

已修复,添加charset=utf-8到Content-Type标头显式指定字符编码修复
func (r *Requester) PostXML(ctx context.Context, endpoint string, xml string, responseStruct interface{}, querystring map[string]string) (*http.Response, error) { payload := bytes.NewBuffer([]byte(xml)) ar := NewAPIRequest("POST", endpoint, payload) if err := r.SetCrumb(ctx, ar); err != nil { return nil, err } ar.SetHeader("Content-Type", "application/xml; charset=utf-8") ar.Suffix = "" return r.Do(ctx, ar, &responseStruct, querystring) }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants