Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm using this code to create a node in Drupal 6:

curl -b cookies.txt -d \
    title="$(sed '1,/sblmtitle/d;/slpstitle/,$d' file.html)" \
    -d form_build_id=form-5312da71abefb3bf1f63f1f2b7cf9105 \
    -d form_token=f65aaefcf6f4b20c9a3d34f5af13ccaf \
    -d form_id=post_node_form -d op=Save http://www.site.com/node/add/post

The file.html contains:

spasi
sblmtitle
Some title here & there
slpstitle

Drupal creates a node with title Some title here. Drupal rejects the character &;

What can I do to make Drupal 6 accept &?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

Ampersand has a special meaning in URLs. In order to pass an real ampersand in a URL you must encode it as %26. You can either make that change with an extra sed expression or just change it in your file.

share|improve this answer
add comment

& is used for separating form fields, use the --data-urlencode option to encode & properly:

curl -b cookies.txt --data-urlencode \
    title="$(sed '1,/sblmtitle/d;/slpstitle/,$d' file.html)" \
    -d form_build_id=form-5312da71abefb3bf1f63f1f2b7cf9105 \
    -d form_token=f65aaefcf6f4b20c9a3d34f5af13ccaf \
    -d form_id=post_node_form -d op=Save http://www.site.com/node/add/post

From the manual page

--data-urlencode
(HTTP) This posts data, similar to the other --data options with the exception that this performs URL-encoding. (Added in 7.18.0)

name=content
This will make curl URL-encode the content part and pass that on. Note that the name part is expected to be URL-encoded already.

share|improve this answer
    
interesting, but not works –  Najib-botak Chin Aug 8 '11 at 11:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.